Commit 0f184476 authored by 前端-许佳敏's avatar 前端-许佳敏

feat: 新增登录cookie

parent 7c024057
......@@ -73,4 +73,4 @@ const router = [
/**
* v2版本 该项目只返回能力中心路由
*/
export default memberCenterRoute
export default router
......@@ -38,7 +38,6 @@
"start:25": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.0.25:8100 USE_ROUTE_CONFIG=true SOCKET_URL=ws://10.0.0.25:9400 yarn start",
"start:v2": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.0.17:8100 USE_ROUTE_CONFIG=true SOCKET_URL=ws://10.0.0.17:9880 yarn start",
"start:v2Preview": "cross-env SITE_ID=1 BACK_GATEWAY=http://10.0.1.220:8100 USE_ROUTE_CONFIG=false SOCKET_URL=ws://10.0.1.220:9400 yarn start"
},
"lint-staged": {
"*.{js,jsx,less,md,json}": [
......@@ -57,6 +56,7 @@
"@formily/antd": "^1.3.3",
"@formily/antd-components": "^1.3.3",
"@types/crypto-js": "^4.0.1",
"@types/js-cookie": "^2.2.6",
"@umijs/hooks": "^1.9.3",
"@umijs/plugin-esbuild": "^1.0.1",
"@umijs/preset-react": "1.x",
......@@ -69,6 +69,7 @@
"crypto-js": "^4.0.0",
"god": "0.2.5",
"immutability-helper": "^3.1.1",
"js-cookie": "^2.2.1",
"lingxi-design": "^2.0.1",
"lingxi-design-ui": "^2.0.4",
"lingxi-editor-core": "^2.0.1",
......
......@@ -9,6 +9,7 @@ import {
import { PublicApi } from '@/services/api';
import { setAuth, setRouters } from '@/utils/auth';
import { encryptedByAES } from '@/utils/cryptoAes';
import { setTokenCookie } from '@/utils/siteCookie';
const LoginWrap: React.FC = () => {
const { redirect } = history.location.query
......@@ -26,6 +27,8 @@ const LoginWrap: React.FC = () => {
message.success("登录成功")
setAuth(data)
setRouters(data.urls)
// 设置同域名cookie缓存
setTokenCookie(data.token)
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
if (redirect) {
window.location.replace(decodeURIComponent(atob(redirect)))
......
/**
* 设置samesite的cookie, 达到多个域名登录信息共享
*/
import Cookie from 'js-cookie'
const TOKEN_KEY = 'siteToken'
export const setTokenCookie = (token: string) => {
Cookie.set(TOKEN_KEY, token, { domain: 'lingxidev.com', secure: true, httpOnly: true, })
}
export const getTokenCookie = () => {
return Cookie.get(TOKEN_KEY)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment