From 9ac254aa405e94241c3c2cd35f3769cdd7fc9dbe Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 12 Jan 2026 14:16:34 +0700 Subject: [PATCH] add update session --- src/app/actions/auth.ts | 5 +++-- src/app/actions/session.ts | 20 ++++++++++++++++++++ src/app/actions/sessions.ts | 23 ----------------------- 3 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 src/app/actions/sessions.ts diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 101eb2c..71650be 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -1,7 +1,7 @@ 'use server' -import { SignupFormSchema, loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions'; -import { createSession, deleteSession, getSessionData } from '@/app/actions/session'; +import { loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions'; +import {createSession, deleteSession, getSessionData, updateSession} from '@/app/actions/session'; import { redirect } from 'next/navigation'; export async function logout() { @@ -301,6 +301,7 @@ export async function tokenLifeExtension() { const parsed = await response.json(); console.log('tokenLifeExtension'); console.log(parsed.message_code); + updateSession(); } } catch (error) { await deleteSession(); diff --git a/src/app/actions/session.ts b/src/app/actions/session.ts index afe76ee..8072506 100644 --- a/src/app/actions/session.ts +++ b/src/app/actions/session.ts @@ -44,6 +44,26 @@ export async function createSession(token: string, email: string) { }); } +export async function updateSession() { + const session = (await cookies()).get('session')?.value + const payload = await decrypt(session) + + if (!session || !payload) { + return null + } + + const expiresAt = new Date(Date.now() + 60 * 60 * 1000); + + const cookieStore = await cookies() + cookieStore.set('session', session, { + httpOnly: true, + secure: false, + expires: expiresAt, + sameSite: 'lax', + path: '/', + }); +} + export async function getSessionData(type: 'token' | 'email'): Promise { const cookieStore = await cookies(); const sessionCookie = cookieStore.get('session')?.value; diff --git a/src/app/actions/sessions.ts b/src/app/actions/sessions.ts deleted file mode 100644 index aabab90..0000000 --- a/src/app/actions/sessions.ts +++ /dev/null @@ -1,23 +0,0 @@ -import 'server-only' -import { cookies } from 'next/headers' -import { decrypt } from '@/app/actions/session' - -export async function updateSession() { - const session = (await cookies()).get('session')?.value - const payload = await decrypt(session) - - if (!session || !payload) { - return null - } - - const expires = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) - - const cookieStore = await cookies() - cookieStore.set('session', session, { - httpOnly: true, - secure: true, - expires: expires, - sameSite: 'lax', - path: '/', - }) -} \ No newline at end of file