add function tokenLifeExtension
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use server'
|
'use server'
|
||||||
import { getSessionData } from '@/app/actions/session';
|
import { getSessionData } from '@/app/actions/session';
|
||||||
import { testUserData, API_BASE_URL } from '@/app/actions/definitions';
|
import { testUserData, API_BASE_URL } from '@/app/actions/definitions';
|
||||||
|
import {tokenLifeExtension} from '@/app/actions/auth';
|
||||||
|
|
||||||
export async function getUserData() {
|
export async function getUserData() {
|
||||||
const userEmail = await getSessionData('email');
|
const userEmail = await getSessionData('email');
|
||||||
@@ -32,6 +33,7 @@ export async function getUserData() {
|
|||||||
|
|
||||||
export async function getUserFilesInfo() {
|
export async function getUserFilesInfo() {
|
||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
|
await tokenLifeExtension();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
|
|||||||
+34
-3
@@ -18,10 +18,10 @@ export async function logout() {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await deleteSession();
|
||||||
|
redirect('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
await deleteSession();
|
|
||||||
redirect('/login');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function authorization(
|
export async function authorization(
|
||||||
@@ -277,3 +277,34 @@ export async function registration(
|
|||||||
|
|
||||||
redirect('/pages/dashboard');
|
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) {
|
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({
|
const session = await encrypt({
|
||||||
token,
|
token,
|
||||||
email,
|
email,
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ const getQueryClientDefaultConfig = () => ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export function makeQueryClient() {
|
export function makeQueryClient() {
|
||||||
return new QueryClient(getQueryClientDefaultConfig())
|
return new QueryClient(getQueryClientDefaultConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getQueryClient = cache(() => {
|
export const getQueryClient = cache(() => {
|
||||||
|
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
return new QueryClient(getQueryClientDefaultConfig())
|
return new QueryClient(getQueryClientDefaultConfig())
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!globalThis.__APP_QUERY_CLIENT__) {
|
if (!globalThis.__APP_QUERY_CLIENT__) {
|
||||||
|
|||||||
Reference in New Issue
Block a user