feat: introduce authentication context

This commit is contained in:
Ali BARIN
2022-03-08 19:50:51 +01:00
committed by Ömer Faruk Aydın
parent 030d886cf7
commit 5d1c4b81e7
8 changed files with 103 additions and 26 deletions

View File

@@ -1,7 +1,19 @@
import { getItem } from 'helpers/storage';
import * as React from 'react';
import { AuthenticationContext } from 'contexts/Authentication';
import type { AuthenticationContextParams } from 'contexts/Authentication';
export default function useAuthentication(): boolean {
const token = getItem('token');
type UseAuthenticationReturn = {
isAuthenticated: boolean;
token: AuthenticationContextParams["token"];
updateToken: AuthenticationContextParams["updateToken"];
};
return Boolean(token);
export default function useAuthentication(): UseAuthenticationReturn {
const authenticationContext = React.useContext(AuthenticationContext);
return {
token: authenticationContext.token,
updateToken: authenticationContext.updateToken,
isAuthenticated: Boolean(authenticationContext.token),
};
}