-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathparseAuth.js
48 lines (45 loc) · 1.59 KB
/
parseAuth.js
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
import { AUTH_LOGIN, AUTH_LOGOUT, AUTH_ERROR, AUTH_CHECK } from 'react-admin';
import Parse from 'parse';
export default ({URL, APP_ID, JAVASCRIPT_KEY}) => {
if (Parse.applicationId === null || Parse.javaScriptKey === null) {
Parse.initialize(APP_ID, JAVASCRIPT_KEY);
Parse.serverURL = URL;
}
return async (type, params) => {
// console.log("parseAuth",type, params);
if (type === AUTH_LOGIN) {
const { username, password } = params;
try {
const user = await Parse.User.logIn(username, password);
return user;
} catch (error) {
throw Error("Wrong username / password");
}
}
if (type === AUTH_LOGOUT) {
try {
await Parse.User.logOut();
return Promise.resolve();
} catch(error) {
throw Error(error.toString());
}
}
if (type === AUTH_ERROR) {
// ...
// Parse.User.logOut().then
return Promise.resolve();
}
if (type === AUTH_CHECK) {
// return Promise.resolve();
// const { resource } = params;
return Parse.User.current() ? Promise.resolve() : Promise.reject();
// if (resource === 'posts') {
// // check credentials for the posts resource
// }
// if (resource === 'comments') {
// // check credentials for the comments resource
// }
}
return Promise.reject('Unknown method');
};
}