feat: 添加生产环境配置,重构 API 请求,更新部署脚本和配置
This commit is contained in:
6
lib/api.ts
Normal file
6
lib/api.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''
|
||||
|
||||
export function apiFetch(input: string, init?: RequestInit): Promise<Response> {
|
||||
const url = input.startsWith('/') ? `${basePath}${input}` : input
|
||||
return fetch(url, init)
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import { createAuthClient } from 'better-auth/react'
|
||||
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || '/studio'
|
||||
const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3001'
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
baseURL: process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000',
|
||||
baseURL: `${appUrl}${basePath}/api/auth`,
|
||||
})
|
||||
|
||||
export const { signIn, signOut, useSession } = authClient
|
||||
|
||||
@@ -9,7 +9,8 @@ export const auth = betterAuth({
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
trustedOrigins: [process.env.BETTER_AUTH_URL || 'http://localhost:3000'],
|
||||
basePath: '/api/auth',
|
||||
trustedOrigins: [process.env.BETTER_AUTH_URL || 'http://localhost:3001'],
|
||||
secret: process.env.BETTER_AUTH_SECRET,
|
||||
session: {
|
||||
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
||||
|
||||
Reference in New Issue
Block a user