yes
This commit is contained in:
@@ -1,43 +1,46 @@
|
||||
'use server'
|
||||
"use server";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
import LoginForm from "@/components/client/admin/loginForm";
|
||||
import ClientAuthHandler from "@/components/client/admin/clientAuthHandler";
|
||||
import CLoginForm from "@/components/client/admin/CLoginForm";
|
||||
import ClientAuthHandler from "@/components/client/admin/CAuthHandler";
|
||||
|
||||
import { serverValidateSessionCookie } from "@/app/lib/actions/actions";
|
||||
import { ReactNode } from "react";
|
||||
import { AuthContext, AuthProps } from "@/providers/providers";
|
||||
|
||||
import { AuthContextProviderProps } from "@/providers";
|
||||
|
||||
interface Props {
|
||||
children?: ReactNode;
|
||||
params?: any;
|
||||
requiredRole?: number;
|
||||
children?: ReactNode;
|
||||
params?: any;
|
||||
requiredRole?: number;
|
||||
} // We interfacing lads
|
||||
|
||||
|
||||
export default async function AuthHandler(props: Props) {
|
||||
const protoKoek = await cookies().get('auth')?.value;
|
||||
const koek = decodeURIComponent(protoKoek ? protoKoek: "");
|
||||
// console.log("koekje:" + koek)
|
||||
let p:AuthProps = {
|
||||
};
|
||||
if(koek){
|
||||
const kd = JSON.parse(koek);
|
||||
if(kd.id && kd.token && kd.user_id){
|
||||
p = {
|
||||
auth: {
|
||||
id:kd.id,
|
||||
token:kd.token,
|
||||
user_id:kd.user_id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const protoKoek = await cookies().get("auth")?.value;
|
||||
const koek = decodeURIComponent(protoKoek ? protoKoek : "");
|
||||
// console.log("koekje:" + koek)
|
||||
let p: AuthContextProviderProps = {};
|
||||
if (koek) {
|
||||
const kd = JSON.parse(koek);
|
||||
if (kd.id && kd.token && kd.user_id) {
|
||||
p = {
|
||||
auth: {
|
||||
id: kd.id,
|
||||
token: kd.token,
|
||||
user_id: kd.user_id,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-row w-[100%] h-[100%]">
|
||||
{!(koek && await serverValidateSessionCookie(koek)) ? <LoginForm>{ }</LoginForm> : <ClientAuthHandler authProps={p}>{props.children}</ClientAuthHandler>}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="flex flex-row w-[100%] h-[100%]">
|
||||
{!(koek && (await serverValidateSessionCookie(koek))) ? (
|
||||
<CLoginForm>{}</CLoginForm>
|
||||
) : (
|
||||
<ClientAuthHandler authProps={p}>
|
||||
{props.children}
|
||||
</ClientAuthHandler>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user