Skip to content

Commit

Permalink
fix react rehydration error caused by not evaluating hook in any case.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebalz committed Aug 3, 2024
1 parent 7c3343e commit 9dc25fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function HomepageHeader() {
);
}

const Login = observer(() => {
const LoginPage = observer(() => {
const sessionStore = useStore('sessionStore');
const { instance } = useMsal();
const isAuthenticated = sessionStore.isLoggedIn || useIsAuthenticated();
const isAuthenticated = useIsAuthenticated();
if (isAuthenticated || NO_AUTH) {
console.log('redirect');
return <Redirect to={'/user'} />;
Expand Down Expand Up @@ -56,4 +56,13 @@ const Login = observer(() => {
</Layout>
);
});

const Login = observer(() => {
const sessionStore = useStore('sessionStore');
if (sessionStore.isLoggedIn || NO_AUTH) {
console.log('redirect');
return <Redirect to={'/user'} />;
}
return <LoginPage />;
});
export default Login;
4 changes: 2 additions & 2 deletions src/stores/SessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SessionStore extends iStore {

@observable.ref private accessor stateRef: State = new State();

@observable accessor authMethod: 'apiKey' | 'msal';
@observable accessor authMethod: 'apiKey' | 'msal' = 'msal';

@observable accessor currentUserId: string | undefined;

Expand All @@ -39,7 +39,7 @@ export class SessionStore extends iStore {
() => this.root.userStore?.current?.id,
(id) => {
if (id) {
const user = this.root.userStore.current;
const user = this.root.userStore.current!;
Storage.set(StorageKey.SessionStore, {
user: { ...user.props, role: Role.USER }
});
Expand Down

0 comments on commit 9dc25fc

Please sign in to comment.