Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show login toaster upon user settings change #1802

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/shared/components/home/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export class Login extends Component<any, State> {
}

case "success": {
UserService.Instance.login(loginRes.data);
UserService.Instance.login({
res: loginRes.data,
});
const site = await HttpService.client.getSite({
auth: myAuth(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/home/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Setup extends Component<any, State> {
if (i.state.registerRes.state == "success") {
const data = i.state.registerRes.data;

UserService.Instance.login(data);
UserService.Instance.login({ res: data });
i.setState({ doneRegisteringUser: true });
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/shared/components/home/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ export class Signup extends Component<any, State> {

// Only log them in if a jwt was set
if (data.jwt) {
UserService.Instance.login(data);
UserService.Instance.login({
res: data,
});

const site = await HttpService.client.getSite({ auth: myAuth() });

Expand Down
4 changes: 3 additions & 1 deletion src/shared/components/person/password-change.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export class PasswordChange extends Component<any, State> {

if (i.state.passwordChangeRes.state === "success") {
const data = i.state.passwordChangeRes.data;
UserService.Instance.login(data);
UserService.Instance.login({
res: data,
});

const site = await HttpService.client.getSite({ auth: myAuth() });
if (site.state === "success") {
Expand Down
11 changes: 9 additions & 2 deletions src/shared/components/person/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,12 @@ export class Settings extends Component<any, SettingsState> {
...i.state.saveUserSettingsForm,
auth: myAuthRequired(),
});

if (saveRes.state === "success") {
UserService.Instance.login(saveRes.data);
UserService.Instance.login({
res: saveRes.data,
showToast: false,
});
Comment on lines +1180 to +1183
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for now, but I always found it odd how the flow for changing settings involves making a call to login. Ideally we'd be able to update the settings without doing that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its def a weird one, should probably be reworked sometime.

toast(I18NextService.i18n.t("saved"));
window.scrollTo(0, 0);
}
Expand All @@ -1198,7 +1202,10 @@ export class Settings extends Component<any, SettingsState> {
auth: myAuthRequired(),
});
if (changePasswordRes.state === "success") {
UserService.Instance.login(changePasswordRes.data);
UserService.Instance.login({
res: changePasswordRes.data,
showToast: false,
});
window.scrollTo(0, 0);
toast(I18NextService.i18n.t("password_changed"));
}
Expand Down
10 changes: 8 additions & 2 deletions src/shared/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ export class UserService {
this.#setJwtInfo();
}

public login(res: LoginResponse) {
public login({
res,
showToast = true,
}: {
res: LoginResponse;
showToast?: boolean;
}) {
const expires = new Date();
expires.setDate(expires.getDate() + 365);
if (isBrowser() && res.jwt) {
toast(I18NextService.i18n.t("logged_in"));
showToast && toast(I18NextService.i18n.t("logged_in"));
document.cookie = cookie.serialize("jwt", res.jwt, {
expires,
secure: isHttps(),
Expand Down