-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthProvider.tsx
41 lines (34 loc) · 1.04 KB
/
AuthProvider.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
/* eslint-disable prefer-promise-reject-errors */
import { CognitoUser, Auth } from "@aws-amplify/auth";
import { AuthProvider } from "react-admin";
export const signIn = Auth.signIn.bind(Auth);
export const login = (params: any) => {
if (params instanceof CognitoUser) {
return Promise.resolve(params);
}
return signIn(params);
};
export const logout = () => Auth.signOut({ global: true });
export const currentSession = () =>
Auth.currentSession().then((session) => {
if (!session) {
return Promise.reject("You need to sign in to access that page.");
}
return session;
});
const authProvider: AuthProvider = {
// authentication
login: (params) => login(params),
checkError: (error) => Promise.resolve(),
checkAuth: (params) => Promise.resolve(),
logout: () => logout(),
getIdentity: async () => {
const session = await currentSession();
return {
id: session.getIdToken().payload.id,
};
},
// authorization
getPermissions: (params) => Promise.resolve({}),
};
export default authProvider;