-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
38 lines (33 loc) · 1.07 KB
/
auth.js
File metadata and controls
38 lines (33 loc) · 1.07 KB
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
import { AsyncStorage } from "react-native";
export const onSignIn = (userObject) => {
console.log('@@@@@@@@ In auth.js, onSignIn function @@@@@@@@@');
console.log(new Date().toTimeString());
return new Promise((resolve, reject) => {
AsyncStorage.setItem("USER_KEY", JSON.stringify(userObject))
.then(res => {
console.log("User signed in and asyncstorage successful");
console.log(res); //res = null
resolve(true);
})
.catch(err => reject(err));
});
}
export const onSignOut = () => AsyncStorage.removeItem("USER_KEY");
export const isSignedIn = () => {
console.log('@@@@@@ In auth.js, isSignedIn function @@@@@@@');
return new Promise((resolve, reject) => {
AsyncStorage.getItem("USER_KEY")
.then(res => {
if ( Boolean(res) ) {
console.log('There is a valid res: ');
console.log(res);
resolve(true);
} else {
console.log('There is not a valid res: ');
console.log(res);
resolve(false);
}
})
.catch(err => reject(err));
});
};