import classnames from 'classnames'; import { cookies } from "next/headers"; import { JWTPayload, jwtVerify } from "jose"; import DashboardHeader from "@/components/DashboardHeader"; import { Schibsted_Grotesk } from 'next/font/google' import { notFound, redirect } from 'next/navigation'; import EligibilitySelector from '@/components/EligibilitySelector'; const font = Schibsted_Grotesk({ subsets: ['latin'] }) const SECRET_KEY = new TextEncoder().encode(process.env.JWT_SECRET_KEY); interface UserJwtPayload extends JWTPayload { user: UserData; } interface UserData { id: string; email: string; name: string; role: string; roleId: string; } export default async function EmployerEligibility() { const cookieStore = await cookies(); const sessionCookie = cookieStore.get("session"); if (!sessionCookie) { redirect('/account/signin') } try { // 2. Extract the raw string token from the cookie object const token = sessionCookie.value; // 3. Verify and decode the JWT using jose const { payload } = await jwtVerify(token, SECRET_KEY) // 3. Cast the payload to your custom interface const data = payload as UserJwtPayload; // const userData = { // plPlanKey: '61', // name: "Bryan Pest Control", // role: 'employer', // roleId: '61' // } const userData = { name: data.user.name, role: data.user.role, roleId: data.user.roleId } if (!data || userData.role !== 'employer') { notFound(); } return ( <>
Eligibility Search