cookie中携带邮箱
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
'use client'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useSelector } from '@/context/app-context'
|
||||
import { get } from '@/service/base'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
/**
|
||||
* IframePostMessage
|
||||
@@ -70,6 +72,28 @@ const IframePostMessage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fetchAndStoreEmail
|
||||
* 调用 /console/api/account/profile 接口,获取当前用户信息,
|
||||
* 并将其中的 email 字段写入浏览器 Cookie。
|
||||
*/
|
||||
const fetchAndStoreEmail = async () => {
|
||||
try {
|
||||
const profile = await get<{ email: string }>('/account/profile')
|
||||
const email = profile?.email || ''
|
||||
if (email) {
|
||||
Cookies.set('email', email, {
|
||||
expires: 365,
|
||||
path: '/',
|
||||
sameSite: 'Lax',
|
||||
secure: globalThis.location.protocol === 'https:',
|
||||
} as any)
|
||||
}
|
||||
} catch {
|
||||
// 忽略接口错误
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (initializedRef.current) return
|
||||
initializedRef.current = true
|
||||
@@ -104,6 +128,13 @@ const IframePostMessage = () => {
|
||||
applyHeaderVisibility()
|
||||
}, [isCurrentWorkspaceManager])
|
||||
|
||||
/**
|
||||
* 初始化时调用接口并写入 email 到 Cookie
|
||||
*/
|
||||
useEffect(() => {
|
||||
fetchAndStoreEmail()
|
||||
}, [])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user