|
| 1 | +import { useEffect } from "react"; |
1 | 2 | import useSleep from "./useSleep";
|
2 | 3 | import useCheckMobile from "./useCheckMobile";
|
3 | 4 |
|
| 5 | +const nil = { isnil: true }; |
| 6 | + |
4 | 7 | let deviceToken = {
|
5 | 8 | current: null,
|
6 | 9 | };
|
@@ -60,6 +63,16 @@ const useMobileToken = () => {
|
60 | 63 | return deviceToken.current;
|
61 | 64 | };
|
62 | 65 |
|
| 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 | + |
63 | 76 | // name should be modified to onReceiveDeviceToken
|
64 | 77 | window.onReceiveDeviceToken = (token) => {
|
65 | 78 | deviceToken.current = token;
|
@@ -115,22 +128,36 @@ const useMobileToken = () => {
|
115 | 128 | console.log(`onReceiveRefreshToken(${token}) called`);
|
116 | 129 | };
|
117 | 130 |
|
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; |
122 | 135 |
|
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 | + }, []); |
125 | 143 |
|
126 | 144 | const storeMobileRefreshToken = async (token) => {
|
127 | 145 | if (isMobile()) {
|
128 | 146 | try {
|
| 147 | + // Android |
129 | 148 | //eslint-disable-next-line
|
130 | 149 | Bridge.AndroidStoreRefreshToken(token);
|
131 | 150 | } catch (error) {
|
132 | 151 | console.log("Error Bridge.AndroidStoreRefreshToken", error);
|
133 | 152 | }
|
| 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 | + } |
134 | 161 | } else {
|
135 | 162 | console.log(
|
136 | 163 | "Not a mobile device, skipping Bridge.AndroidStoreRefreshToken call"
|
|
0 commit comments