优化登录流程,添加白名单管理功能,调整页面布局与样式
This commit is contained in:
@@ -10,13 +10,12 @@ export interface LoginParams {
|
||||
}
|
||||
|
||||
type LoginResp = {
|
||||
token: string
|
||||
access_token: string
|
||||
refresh_token: string
|
||||
expires: number
|
||||
auth: AuthContext
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function login(props: LoginParams): Promise<ApiResponse> {
|
||||
try {
|
||||
// 尝试登录
|
||||
@@ -35,13 +34,20 @@ export async function login(props: LoginParams): Promise<ApiResponse> {
|
||||
const future = data.expires - current
|
||||
|
||||
// 保存到 cookies
|
||||
console.log("token!!!!", data)
|
||||
const cookieStore = await cookies()
|
||||
cookieStore.set('auth_token', data.token, {
|
||||
cookieStore.set('auth_token', data.access_token, {
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
maxAge: Math.max(future, 0),
|
||||
})
|
||||
cookieStore.set('auth_refresh', data.refresh_token, {
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
maxAge: 7 * 24 * 3600,
|
||||
})
|
||||
cookieStore.set('auth_info', JSON.stringify(data.auth), {
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
|
||||
48
src/actions/whitelist.ts
Normal file
48
src/actions/whitelist.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
'use server'
|
||||
import {callWithUserToken, PageRecord} from '@/lib/api'
|
||||
|
||||
type Whitelist = {
|
||||
id: number
|
||||
host: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
remark: string
|
||||
}
|
||||
|
||||
async function listWhitelist(props: {
|
||||
page: number
|
||||
size: number
|
||||
}) {
|
||||
return await callWithUserToken<PageRecord<Whitelist>>('/api/whitelist/list', props)
|
||||
}
|
||||
|
||||
async function createWhitelist(props: {
|
||||
host: string
|
||||
remark?: string
|
||||
}) {
|
||||
console.log(props)
|
||||
return await callWithUserToken('/api/whitelist/create', props)
|
||||
}
|
||||
|
||||
async function updateWhitelist(props: {
|
||||
id: number
|
||||
host?: string
|
||||
remark?: string
|
||||
}) {
|
||||
console.log(props)
|
||||
return await callWithUserToken('/api/whitelist/update', props)
|
||||
}
|
||||
|
||||
async function removeWhitelist(props: {
|
||||
id: number
|
||||
}[]) {
|
||||
return await callWithUserToken('/api/whitelist/remove', props)
|
||||
}
|
||||
|
||||
export {
|
||||
listWhitelist,
|
||||
createWhitelist,
|
||||
updateWhitelist,
|
||||
removeWhitelist,
|
||||
type Whitelist,
|
||||
}
|
||||
Reference in New Issue
Block a user