mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-12 06:55:01 +02:00
pass user object to user context
This commit is contained in:
parent
61fca6a1f6
commit
41cbde1474
6 changed files with 23 additions and 12 deletions
|
@ -100,5 +100,6 @@ process.env.NEXT_PUBLIC_INTERNAL_API_BASE_URL = new URL(
|
|||
"/api/v1",
|
||||
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`,
|
||||
).href;
|
||||
process.env.NEXT_PUBLIC_APP_NAME = parsedConfig.data.app.name;
|
||||
|
||||
export default parsedConfig.data;
|
||||
|
|
|
@ -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", {
|
||||
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||
"/user",
|
||||
{
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`
|
||||
}
|
||||
});
|
||||
return true;
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue