-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathuse-auth0.tsx
More file actions
33 lines (31 loc) · 827 Bytes
/
use-auth0.tsx
File metadata and controls
33 lines (31 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useContext } from 'react';
import { User } from '@auth0/auth0-spa-js';
import Auth0Context, { Auth0ContextInterface } from './auth0-context';
/**
* ```js
* const {
* // Auth state:
* error,
* isAuthenticated,
* isLoading,
* user,
* // Auth methods:
* getAccessTokenSilently,
* getAccessTokenWithPopup,
* getIdTokenClaims,
* exchangeToken,
* loginWithRedirect,
* loginWithPopup,
* logout,
* } = useAuth0<TUser>();
* ```
*
* Use the `useAuth0` hook in your components to access the auth state and methods.
*
* TUser is an optional type param to provide a type to the `user` field.
*/
const useAuth0 = <TUser extends User = User>(
context = Auth0Context
): Auth0ContextInterface<TUser> =>
useContext(context) as Auth0ContextInterface<TUser>;
export default useAuth0;