-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): user is not redirected to Login page after requesting pass…
…word reset link
- Loading branch information
“bc-yevhenii-buliuk”
committed
Jun 6, 2024
1 parent
19a3d14
commit 7470b1f
Showing
6 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/app/[locale]/(default)/login/_components/login-status-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use client'; | ||
|
||
import { createContext, useContext, useState, useEffect, PropsWithChildren } from 'react'; | ||
|
||
export interface LoginState { | ||
status: 'idle' | 'success'; | ||
message?: string; | ||
} | ||
|
||
export const LoginStatusContext = createContext<{ | ||
loginState: LoginState; | ||
setLoginState: (state: LoginState | ((prevState: LoginState) => LoginState)) => void; | ||
} | null>(null); | ||
|
||
export const LoginStatusProvider = ({ children }: PropsWithChildren) => { | ||
const [loginState, setLoginState] = useState<LoginState>({status: 'idle', message: ''}); | ||
|
||
useEffect(() => { | ||
if (loginState.status !== 'idle') { | ||
setTimeout(() => { | ||
setLoginState({ status: 'idle', message: '' }); | ||
}, 3000); | ||
} | ||
}, [loginState, setLoginState]); | ||
|
||
return ( | ||
<LoginStatusContext.Provider value={{loginState, setLoginState}}> | ||
{children} | ||
</LoginStatusContext.Provider> | ||
) | ||
} | ||
|
||
export function useLoginStatusContext() { | ||
const context = useContext(LoginStatusContext); | ||
|
||
if (!context) { | ||
throw new Error('useLoginStatusContext must be used within a LoginStatusProvider'); | ||
} | ||
|
||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { LoginStatusProvider } from './_components/login-status-provider'; | ||
|
||
export default function LoginLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<LoginStatusProvider> | ||
{children} | ||
</LoginStatusProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters