Skip to content

Commit 3aec709

Browse files
committed
Update useMobileToken.js
1 parent 44e9857 commit 3aec709

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/hooks/useMobileToken.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { useEffect } from "react";
12
import useSleep from "./useSleep";
23
import useCheckMobile from "./useCheckMobile";
34

5+
const nil = { isnil: true };
6+
47
let deviceToken = {
58
current: null,
69
};
@@ -60,6 +63,16 @@ const useMobileToken = () => {
6063
return deviceToken.current;
6164
};
6265

66+
useEffect(() => {
67+
// name should be modified to onReceiveDeviceToken
68+
window.onReceiveDeviceToken = (token) => {
69+
deviceToken.current = token;
70+
deviceLock.current = false;
71+
72+
console.log(`onReceiveDeviceToken(${token}) called`);
73+
};
74+
}, []);
75+
6376
// name should be modified to onReceiveDeviceToken
6477
window.onReceiveDeviceToken = (token) => {
6578
deviceToken.current = token;
@@ -115,22 +128,36 @@ const useMobileToken = () => {
115128
console.log(`onReceiveRefreshToken(${token}) called`);
116129
};
117130

118-
// name should be modified to onReceiveAuthToken
119-
window.onReceiveAuthToken = (token) => {
120-
refreshToken.current = token;
121-
refreshLock.current = false;
131+
useEffect(() => {
132+
window.onReceiveAuthToken = (token) => {
133+
refreshToken.current = token;
134+
refreshLock.current = false;
122135

123-
console.log(`onReceiveAuthToken(${token}) called`);
124-
};
136+
console.log(`onReceiveAuthToken(${token}) called`);
137+
};
138+
139+
window.onReceiveTokenStoredAck = () => {
140+
console.log(`onReceiveTokenStoredAck() called`);
141+
};
142+
}, []);
125143

126144
const storeMobileRefreshToken = async (token) => {
127145
if (isMobile()) {
128146
try {
147+
// Android
129148
//eslint-disable-next-line
130149
Bridge.AndroidStoreRefreshToken(token);
131150
} catch (error) {
132151
console.log("Error Bridge.AndroidStoreRefreshToken", error);
133152
}
153+
154+
try {
155+
// Flutter
156+
//eslint-disable-next-line
157+
FlutterStoreAuthToken.postMessage(token);
158+
} catch (error) {
159+
console.log("Error FlutterStoreAuthToken.postMessage(token);", error);
160+
}
134161
} else {
135162
console.log(
136163
"Not a mobile device, skipping Bridge.AndroidStoreRefreshToken call"

0 commit comments

Comments
 (0)