Files
automatisch/packages/web/src/hooks/useAuthentication.ts
2022-11-05 23:57:33 +01:00

20 lines
659 B
TypeScript

import * as React from 'react';
import { AuthenticationContext } from 'contexts/Authentication';
import type { AuthenticationContextParams } from 'contexts/Authentication';
type UseAuthenticationReturn = {
isAuthenticated: boolean;
token: AuthenticationContextParams['token'];
updateToken: AuthenticationContextParams['updateToken'];
};
export default function useAuthentication(): UseAuthenticationReturn {
const authenticationContext = React.useContext(AuthenticationContext);
return {
token: authenticationContext.token,
updateToken: authenticationContext.updateToken,
isAuthenticated: Boolean(authenticationContext.token),
};
}