-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.re
44 lines (40 loc) · 1.36 KB
/
Utils.re
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
open ReactNative;
// Checks the auth status and send to a route. This got the unmounted app warnings to stop though still learning why.
let checkAuthWithRoute = (~navigation: ReactNavigation.navigationProp(unit)) =>
AsyncStorage.getItem("userToken")
|> Js.Promise.then_(stringOrNull => {
// This will switch to the App screen or Auth screen and this loading screen will be unmounted and thrown away.
Js.log2("CHECKING_AUTH_TOKEN", stringOrNull);
switch (Js.Null.toOption(stringOrNull)) {
| None => Js.Promise.resolve(navigation##push("SignIn"))
| Some(_stringOrNull) => Js.Promise.resolve(navigation##push("App"))
};
});
let signOutAsync = (~navigation: ReactNavigation.navigationProp(unit)) => {
Js.Promise.
/* begin call to AsyncStorage */
(
AsyncStorage.clear()
|> then_(_result =>
{
resolve(navigation##push("AuthLoading"));
}
|> resolve
)
|> ignore
);
};
let signInAsync = (~navigation: ReactNavigation.navigationProp(unit)) => {
Js.Promise.
/* begin call to AsyncStorage */
(
AsyncStorage.setItem("userToken", "abc")
|> then_(_result =>
{
resolve(navigation##push("App"));
}
// resolve(navigation##push("AuthLoading"));
|> resolve
)
|> ignore
)};