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

Original url destinations like experiment detail page will not redirect to home after login #1143

Merged
merged 4 commits into from
Nov 21, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/projects/upgrade/src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class AuthService {

initializeUserSession(): void {
const currentUser = this.getUserFromBrowserStorage();
this.setRedirectionUrl(window.location.pathname);

if (currentUser) {
this.handleAutomaticLogin(currentUser);
} else {
Expand Down Expand Up @@ -106,6 +108,7 @@ export class AuthService {
.login(user)
.pipe(
tap((res: User) => {
console.log(`^^^ Do Login: ${window.location.href}`);
this.store$.dispatch(AuthActions.actionLoginSuccess());
this.deferSetUserInfoAfterNavigateEnd(res, googleCredential);
}),
Expand Down Expand Up @@ -152,6 +155,7 @@ export class AuthService {
}

setRedirectionUrl(redirectUrl: string): void {
console.log({ redirectUrl });
this.store$.dispatch(AuthActions.actionSetRedirectUrl({ redirectUrl }));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface UserPermission {
export interface AuthState {
isLoggedIn: boolean;
isAuthenticating: boolean;
redirectUrl?: string;
redirectUrl: string;
user: User;
googleCredential: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const initialState: AuthState = {
isAuthenticating: false,
user: null,
googleCredential: null,
redirectUrl: '/home',
};

const reducer = createReducer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ describe('clearState', () => {
settings: {
theme: ThemeOptions.DARK_THEME,
},
auth: {
isLoggedIn: false,
isAuthenticating: false,
user: null,
googleCredential: null,
redirectUrl: '/home',
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to set any attributes (besides redirectUrl) here, to test that they get set to the default values when clearState is called? The other two attributes in 'settings', for instance, aren't set here. If we do set them, it might be a more definitive test if they're initially set to different values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i updated the specs to make this a little more explicitly tested

};

beforeEach(() => {
Expand All @@ -25,6 +32,13 @@ describe('clearState', () => {
toCheckAuth: null,
toFilterMetric: null,
},
auth: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the 'it' string read 'should reset settings and auth state...'?

isLoggedIn: false,
isAuthenticating: false,
user: null,
googleCredential: null,
redirectUrl: '/home',
},
};

const newState = metaReducer(mockState, actionLogoutSuccess());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as AuthActions from '../auth/store/auth.actions';
import { ExperimentLocalStorageKeys } from '../experiments/store/experiments.model';
import { LocalStorageService } from '../local-storage/local-storage.service';
import { SettingsState } from '../settings/store/settings.model';
import { AuthState } from '../auth/store/auth.models';

export function clearState(reducer) {
return (state, action: Action) => {
Expand All @@ -12,10 +13,18 @@ export function clearState(reducer) {
toCheckAuth: null,
toFilterMetric: null,
};
const authState: AuthState = {
isLoggedIn: false,
isAuthenticating: false,
user: null,
googleCredential: null,
redirectUrl: state.auth.redirectUrl,
};
const localStorageService = new LocalStorageService();

state = {
settings: settingState, // Used to persist theme,
auth: authState, // Used to persist redirectUrl
};

Object.values(ExperimentLocalStorageKeys).forEach((key) => {
Expand Down
Loading