22 lines
657 B
TypeScript
22 lines
657 B
TypeScript
'use server'
|
|
|
|
import 'server-only'
|
|
|
|
import { cookies } from 'next/headers'
|
|
import {cache} from "react";
|
|
import {sendRequestwToken} from "@/app/actions/auth";
|
|
import {TokenIsValid} from "@/app/actions/interfaces";
|
|
|
|
export const verifySession = cache(async () => {
|
|
const cookie = (await cookies()).get('token')?.value
|
|
|
|
const resp = await sendRequestwToken(`${process.env.API_ENDPOINT}/token/validate`,'GET')
|
|
|
|
if (!cookie || resp === null) {
|
|
return { isAuth: false, token: cookie }
|
|
}
|
|
|
|
const is_valid = (await (resp as Response).json()) as TokenIsValid
|
|
|
|
return { isAuth: is_valid.is_valid, token: cookie }
|
|
}) |