add update session
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
import { SignupFormSchema, loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions';
|
import { loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions';
|
||||||
import { createSession, deleteSession, getSessionData } from '@/app/actions/session';
|
import {createSession, deleteSession, getSessionData, updateSession} from '@/app/actions/session';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
export async function logout() {
|
export async function logout() {
|
||||||
@@ -301,6 +301,7 @@ export async function tokenLifeExtension() {
|
|||||||
const parsed = await response.json();
|
const parsed = await response.json();
|
||||||
console.log('tokenLifeExtension');
|
console.log('tokenLifeExtension');
|
||||||
console.log(parsed.message_code);
|
console.log(parsed.message_code);
|
||||||
|
updateSession();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await deleteSession();
|
await deleteSession();
|
||||||
|
|||||||
@@ -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<string | null> {
|
export async function getSessionData(type: 'token' | 'email'): Promise<string | null> {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
const sessionCookie = cookieStore.get('session')?.value;
|
const sessionCookie = cookieStore.get('session')?.value;
|
||||||
|
|||||||
@@ -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: '/',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user