aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/NativeInterface.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-08-27 12:51:32 -0700
committerAnton Tananaev <anton@traccar.org>2022-08-27 12:51:32 -0700
commitb4a769e15fb18d854af56c24e39b0b72fff273a0 (patch)
treeeaf1d43df634de82dc7731a8e53636a91db5a94b /modern/src/common/components/NativeInterface.js
parentc0fcac0d1956caa2c426f1b265ccab7bdfc007bc (diff)
downloadtrackermap-web-b4a769e15fb18d854af56c24e39b0b72fff273a0.tar.gz
trackermap-web-b4a769e15fb18d854af56c24e39b0b72fff273a0.tar.bz2
trackermap-web-b4a769e15fb18d854af56c24e39b0b72fff273a0.zip
Support biometric authentication
Diffstat (limited to 'modern/src/common/components/NativeInterface.js')
-rw-r--r--modern/src/common/components/NativeInterface.js33
1 files changed, 18 insertions, 15 deletions
diff --git a/modern/src/common/components/NativeInterface.js b/modern/src/common/components/NativeInterface.js
index 4e6ad4fe..d43b678c 100644
--- a/modern/src/common/components/NativeInterface.js
+++ b/modern/src/common/components/NativeInterface.js
@@ -14,37 +14,40 @@ export const nativePostMessage = (message) => {
}
};
-const listeners = new Set();
+export const handleLoginTokenListeners = new Set();
+window.handleLoginToken = (token) => {
+ handleLoginTokenListeners.forEach((listener) => listener(token));
+};
+
+const updateNotificationTokenListeners = new Set();
window.updateNotificationToken = (token) => {
- listeners.forEach((listener) => listener(token));
+ updateNotificationTokenListeners.forEach((listener) => listener(token));
};
const NativeInterface = () => {
const dispatch = useDispatch();
const user = useSelector((state) => state.session.user);
- const [token, setToken] = useState(null);
+ const [notificationToken, setNotificationToken] = useState(null);
useEffect(() => {
- const listener = (token) => setToken(token);
- listeners.add(listener);
- return () => {
- listeners.delete(listener);
- };
- }, [setToken]);
+ const listener = (token) => setNotificationToken(token);
+ updateNotificationTokenListeners.add(listener);
+ return () => updateNotificationTokenListeners.delete(listener);
+ }, [setNotificationToken]);
useEffectAsync(async () => {
- if (user && token) {
- window.localStorage.setItem('notificationToken', token);
- setToken(null);
+ if (user && notificationToken) {
+ window.localStorage.setItem('notificationToken', notificationToken);
+ setNotificationToken(null);
const tokens = user.attributes.notificationTokens?.split(',') || [];
- if (!tokens.includes(token)) {
+ if (!tokens.includes(notificationToken)) {
const updatedUser = {
...user,
attributes: {
...user.attributes,
- notificationTokens: [...tokens.slice(-2), token].join(','),
+ notificationTokens: [...tokens.slice(-2), notificationToken].join(','),
},
};
@@ -61,7 +64,7 @@ const NativeInterface = () => {
}
}
}
- }, [user, token, setToken]);
+ }, [user, notificationToken, setNotificationToken]);
return null;
};