-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserContext.tsx
57 lines (47 loc) · 1.14 KB
/
UserContext.tsx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { createContext } from 'react';
export type UserInfo = {
/**
* Access token for backend
*/
token?: string;
/**
* Email as provided by user during EGI registration
*/
email?: string;
/**
* Whether the user is an administrator (= EGI user has the required entitlements)
*/
admin: boolean;
/**
* Whether the user has completed registration on the backend
*/
registered: boolean;
/**
* Shorthand to check if the user is logged in
*/
loggedIn: boolean;
/**
* Whether any component is still loading. Useful to prevent premature warnings or redirects.
*/
loading: boolean;
/**
* Callbacks to log the user in or out
*/
login?: () => void;
logout?: () => void;
};
/**
* Default/fallback user data when the user is not authenticated
*/
export const emptyUser: UserInfo = {
token: undefined,
email: undefined,
admin: false,
registered: false,
loggedIn: false,
loading: false,
login: () => undefined,
logout: () => undefined,
};
const UserContext = createContext(emptyUser);
export default UserContext;