feat: local device token

This commit is contained in:
Tristan Yang
2023-01-18 22:18:53 +08:00
parent 503089ae8d
commit e01ab652a4
4 changed files with 19 additions and 7 deletions
+1
View File
@@ -110,6 +110,7 @@ export const KEY_EXPIRE = "VOCECHAT_TOKEN_EXPIRE";
export const KEY_REFRESH_TOKEN = "VOCECHAT_REFRESH_TOKEN";
export const KEY_UID = "VOCECHAT_CURR_UID";
export const KEY_DEVICE_ID = "VOCECHAT_DEVICE_KEY";
export const KEY_DEVICE_TOKEN = "VOCECHAT_DEVICE_TOKEN";
export const KEY_USERS_VERSION = "VOCECHAT_USERS_VERSION";
export const KEY_AFTER_MID = "VOCECHAT_AFTER_MID";
export const KEY_PWA_INSTALLED = "VOCECHAT_PWA_INSTALLED";
+5 -4
View File
@@ -2,7 +2,7 @@ import { createApi } from "@reduxjs/toolkit/query/react";
import { nanoid } from "@reduxjs/toolkit";
import baseQuery from "./base.query";
import { setAuthData, updateToken, resetAuthData, updateInitialized } from "../slices/auth.data";
import BASE_URL, { KEY_DEVICE_ID, KEY_LOCAL_MAGIC_TOKEN } from "../config";
import BASE_URL, { KEY_DEVICE_ID, KEY_DEVICE_TOKEN, KEY_LOCAL_MAGIC_TOKEN } from "../config";
import {
AuthData,
CredentialResponse,
@@ -13,11 +13,12 @@ import {
const getDeviceId = () => {
let d = localStorage.getItem(KEY_DEVICE_ID);
let dt = localStorage.getItem(KEY_DEVICE_TOKEN) || "";
if (!d) {
d = `web:${nanoid()}`;
localStorage.setItem(KEY_DEVICE_ID, d);
}
return d;
return { device: d, device_token: dt };
};
export const authApi = createApi({
@@ -30,8 +31,8 @@ export const authApi = createApi({
method: "POST",
body: {
credential,
device: getDeviceId(),
device_token: "test"
device: getDeviceId().device,
device_token: getDeviceId().device_token
}
}),
transformResponse: (data: AuthData) => {