-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into issue#6770
- Loading branch information
Showing
58 changed files
with
775 additions
and
338 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
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
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
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
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
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 |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import { createContext, useContext } from "react"; | ||
import { UserModel } from "../../Components/Users/models"; | ||
import { RequestResult } from "../../Utils/request/types"; | ||
import { JwtTokenObtainPair, LoginCredentials } from "../../Redux/api"; | ||
|
||
export const AuthUserContext = createContext<UserModel | null>(null); | ||
type SignInReturnType = RequestResult<JwtTokenObtainPair>; | ||
|
||
export default function useAuthUser() { | ||
const user = useContext(AuthUserContext); | ||
type AuthContextType = { | ||
user: UserModel | undefined; | ||
signIn: (creds: LoginCredentials) => Promise<SignInReturnType>; | ||
signOut: () => Promise<void>; | ||
}; | ||
|
||
if (!user) { | ||
throw new Error("useAuthUser must be used within an AuthUserProvider"); | ||
export const AuthUserContext = createContext<AuthContextType | null>(null); | ||
|
||
export const useAuthContext = () => { | ||
const ctx = useContext(AuthUserContext); | ||
if (!ctx) { | ||
throw new Error( | ||
"'useAuthContext' must be used within 'AuthUserProvider' only" | ||
); | ||
} | ||
return ctx; | ||
}; | ||
|
||
export default function useAuthUser() { | ||
const user = useAuthContext().user; | ||
if (!user) { | ||
throw new Error("'useAuthUser' must be used within 'AppRouter' only"); | ||
} | ||
return user; | ||
} |
Oops, something went wrong.