移除 cookie 的 secure 属性
This commit is contained in:
@@ -31,7 +31,6 @@ RUN pnpm run build
|
|||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
|||||||
@@ -40,25 +40,21 @@ export async function login(props: LoginParams): Promise<ApiResponse> {
|
|||||||
cookieStore.set('auth_token', data.access_token, {
|
cookieStore.set('auth_token', data.access_token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: Math.max(future, 0),
|
maxAge: Math.max(future, 0),
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_refresh', data.refresh_token, {
|
cookieStore.set('auth_refresh', data.refresh_token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 7 * 24 * 3600,
|
maxAge: 7 * 24 * 3600,
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_info', JSON.stringify(data.auth), {
|
cookieStore.set('auth_info', JSON.stringify(data.auth), {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 7 * 24 * 3600,
|
maxAge: 7 * 24 * 3600,
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_profile', JSON.stringify(data.profile), {
|
cookieStore.set('auth_profile', JSON.stringify(data.profile), {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 7 * 24 * 3600,
|
maxAge: 7 * 24 * 3600,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -85,25 +81,21 @@ export async function logout() {
|
|||||||
cookieStore.set('auth_token', '', {
|
cookieStore.set('auth_token', '', {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: -1,
|
maxAge: -1,
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_refresh', '', {
|
cookieStore.set('auth_refresh', '', {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: -1,
|
maxAge: -1,
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_info', '', {
|
cookieStore.set('auth_info', '', {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: -1,
|
maxAge: -1,
|
||||||
})
|
})
|
||||||
cookieStore.set('auth_profile', '', {
|
cookieStore.set('auth_profile', '', {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: -1,
|
maxAge: -1,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,7 +132,6 @@ export async function getProfile(refresh: boolean = false) {
|
|||||||
cookie.set('auth_profile', JSON.stringify(result.data), {
|
cookie.set('auth_profile', JSON.stringify(result.data), {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 7 * 24 * 3600,
|
maxAge: 7 * 24 * 3600,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
'use server'
|
'use server'
|
||||||
// 验证验证码函数
|
|
||||||
import {cookies} from 'next/headers'
|
import {cookies} from 'next/headers'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
import {ApiResponse} from '@/lib/api'
|
import {ApiResponse} from '@/lib/api'
|
||||||
@@ -43,8 +42,6 @@ export default async function verify(props: VerifyParams): Promise<ApiResponse>
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function verifyCaptcha(userInput: string): Promise<boolean> {
|
async function verifyCaptcha(userInput: string): Promise<boolean> {
|
||||||
console.log("验证验证码:", userInput)
|
|
||||||
|
|
||||||
const cookieStore = await cookies()
|
const cookieStore = await cookies()
|
||||||
const hash = cookieStore.get('captcha_hash')?.value
|
const hash = cookieStore.get('captcha_hash')?.value
|
||||||
const salt = cookieStore.get('captcha_salt')?.value
|
const salt = cookieStore.get('captcha_salt')?.value
|
||||||
@@ -63,7 +60,6 @@ async function verifyCaptcha(userInput: string): Promise<boolean> {
|
|||||||
|
|
||||||
// 比较哈希值
|
// 比较哈希值
|
||||||
const isValid = hash === userInputHash
|
const isValid = hash === userInputHash
|
||||||
console.log('验证码验证结果:', isValid, hash, userInputHash)
|
|
||||||
|
|
||||||
// 验证后删除验证码cookie,防止重复使用
|
// 验证后删除验证码cookie,防止重复使用
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
|
|||||||
@@ -156,13 +156,11 @@ async function getUserToken(refresh = false): Promise<string> {
|
|||||||
cookie.set('auth_token', nextAccessToken, {
|
cookie.set('auth_token', nextAccessToken, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: Math.max(expiresIn, 0),
|
maxAge: Math.max(expiresIn, 0),
|
||||||
})
|
})
|
||||||
cookie.set('auth_refresh', nextRefreshToken, {
|
cookie.set('auth_refresh', nextRefreshToken, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 7 * 24 * 3600, // 7天
|
maxAge: 7 * 24 * 3600, // 7天
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,11 @@ export async function GET(request: Request) {
|
|||||||
.set('captcha_hash', hash, {
|
.set('captcha_hash', hash, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 60,
|
maxAge: 60,
|
||||||
})
|
})
|
||||||
.set('captcha_salt', salt, {
|
.set('captcha_salt', salt, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: process.env.NODE_ENV === 'production',
|
|
||||||
maxAge: 60,
|
maxAge: 60,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user