diff --git a/src/app/actions/action.ts b/src/app/actions/action.ts index 202f6d0..ec24425 100644 --- a/src/app/actions/action.ts +++ b/src/app/actions/action.ts @@ -1,6 +1,7 @@ 'use server' import { getSessionData } from '@/app/actions/session'; import { testUserData, API_BASE_URL } from '@/app/actions/definitions'; +import {tokenLifeExtension} from '@/app/actions/auth'; export async function getUserData() { const userEmail = await getSessionData('email'); @@ -32,6 +33,7 @@ export async function getUserData() { export async function getUserFilesInfo() { const token = await getSessionData('token'); + await tokenLifeExtension(); try { const response = await fetch(`${API_BASE_URL}/api/v1/data`, { diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index e84c52c..101eb2c 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -18,10 +18,10 @@ export async function logout() { }); } catch (error) { throw error; + } finally { + await deleteSession(); + redirect('/login'); } - - await deleteSession(); - redirect('/login'); } export async function authorization( @@ -276,4 +276,35 @@ export async function registration( } redirect('/pages/dashboard'); +} + +export async function tokenLifeExtension() { + const token = await getSessionData('token'); + + try { + const response = await fetch(`${API_BASE_URL}/api/v1/data`, { + method: 'POST', + headers: { + "Content-Type": "application/json", + "Accept": "application/json", + }, + body: JSON.stringify({ + version: 1, + msg_id: 20008, + message_body: { + token: token + } + }), + }); + + if (response.ok) { + const parsed = await response.json(); + console.log('tokenLifeExtension'); + console.log(parsed.message_code); + } + } catch (error) { + await deleteSession(); + redirect('/login'); + throw error; + } } \ No newline at end of file diff --git a/src/app/actions/session.ts b/src/app/actions/session.ts index 009240a..afe76ee 100644 --- a/src/app/actions/session.ts +++ b/src/app/actions/session.ts @@ -27,7 +27,7 @@ export async function decrypt(session: string | undefined = '') { } export async function createSession(token: string, email: string) { - const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000); + const expiresAt = new Date(Date.now() + 60 * 60 * 1000); const session = await encrypt({ token, email, diff --git a/src/app/providers/getQueryClient.ts b/src/app/providers/getQueryClient.ts index 7c45717..8483c87 100644 --- a/src/app/providers/getQueryClient.ts +++ b/src/app/providers/getQueryClient.ts @@ -12,13 +12,13 @@ const getQueryClientDefaultConfig = () => ({ }) export function makeQueryClient() { - return new QueryClient(getQueryClientDefaultConfig()) + return new QueryClient(getQueryClientDefaultConfig()); } export const getQueryClient = cache(() => { if (typeof window === 'undefined') { - return new QueryClient(getQueryClientDefaultConfig()) + return new QueryClient(getQueryClientDefaultConfig()) } else { // @ts-ignore if (!globalThis.__APP_QUERY_CLIENT__) {