-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathauthProvider.ts
29 lines (29 loc) · 1.06 KB
/
authProvider.ts
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
export const authProvider = {
// called when the user attempts to log in
login: ({ username }: { username: string }) => {
localStorage.setItem('username', username);
// accept all username/password combinations
return Promise.resolve();
},
// called when the user clicks on the logout button
logout: () => {
localStorage.removeItem('username');
return Promise.resolve();
},
// called when the API returns an error
checkError: ({ status }: { status: number }) => {
if (status === 401 || status === 403) {
localStorage.removeItem('username');
return Promise.reject();
}
return Promise.resolve();
},
// called when the user navigates to a new location, to check for authentication
checkAuth: () => {
return localStorage.getItem('username')
? Promise.resolve()
: Promise.reject();
},
// called when the user navigates to a new location, to check for permissions / roles
getPermissions: () => Promise.resolve(),
};