add function tokenLifeExtension
This commit is contained in:
@@ -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`, {
|
||||
|
||||
+34
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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__) {
|
||||
|
||||
Reference in New Issue
Block a user