mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-01 15:49:08 +00:00
pass user object to user context
This commit is contained in:
@@ -3,7 +3,7 @@ import "./globals.css";
|
||||
import { Roboto } from "next/font/google";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Pangolin",
|
||||
title: process.env.NEXT_PUBLIC_APP_NAME,
|
||||
description: "",
|
||||
};
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ export default async function Page() {
|
||||
redirect("/auth/login");
|
||||
}
|
||||
|
||||
console.log(user);
|
||||
|
||||
return (
|
||||
<>
|
||||
<LandingProvider user={user}>
|
||||
<p>You are logged in!</p>
|
||||
<p>Logged in as {user.email}</p>
|
||||
</LandingProvider>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { createContext } from "react";
|
||||
|
||||
export const UserContext = createContext<boolean | null>(null);
|
||||
export const UserContext = createContext<GetUserResponse | null>(null);
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
import { internal } from "@app/api";
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function verifySession() {
|
||||
export async function verifySession(): Promise<GetUserResponse | null> {
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
|
||||
try {
|
||||
await internal.get("/user", {
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`
|
||||
}
|
||||
});
|
||||
return true;
|
||||
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||
"/user",
|
||||
{
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data.data;
|
||||
} catch {
|
||||
return false
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { UserContext } from "@app/contexts/userContext";
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
type LandingProviderProps = {
|
||||
user: boolean ;
|
||||
user: GetUserResponse;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user