Init NextJS, Implement Login and more
This commit is contained in:
22
src/components/DAL/dal.ts
Normal file
22
src/components/DAL/dal.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
'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 }
|
||||
})
|
||||
Reference in New Issue
Block a user