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",
|
"/api/v1",
|
||||||
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`,
|
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`,
|
||||||
).href;
|
).href;
|
||||||
|
process.env.NEXT_PUBLIC_APP_NAME = parsedConfig.data.app.name;
|
||||||
|
|
||||||
export default parsedConfig.data;
|
export default parsedConfig.data;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import "./globals.css";
|
||||||
import { Roboto } from "next/font/google";
|
import { Roboto } from "next/font/google";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Pangolin",
|
title: process.env.NEXT_PUBLIC_APP_NAME,
|
||||||
description: "",
|
description: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,12 @@ export default async function Page() {
|
||||||
redirect("/auth/login");
|
redirect("/auth/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(user);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LandingProvider user={user}>
|
<LandingProvider user={user}>
|
||||||
<p>You are logged in!</p>
|
<p>Logged in as {user.email}</p>
|
||||||
</LandingProvider>
|
</LandingProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { GetUserResponse } from "@server/routers/user";
|
||||||
import { createContext } from "react";
|
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 { internal } from "@app/api";
|
||||||
|
import { GetUserResponse } from "@server/routers/user";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export async function verifySession() {
|
export async function verifySession(): Promise<GetUserResponse | null> {
|
||||||
const sessionId = cookies().get("session")?.value ?? null;
|
const sessionId = cookies().get("session")?.value ?? null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await internal.get("/user", {
|
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||||
headers: {
|
"/user",
|
||||||
Cookie: `session=${sessionId}`
|
{
|
||||||
}
|
headers: {
|
||||||
});
|
Cookie: `session=${sessionId}`,
|
||||||
return true;
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.data.data;
|
||||||
} catch {
|
} catch {
|
||||||
return false
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { UserContext } from "@app/contexts/userContext";
|
import { UserContext } from "@app/contexts/userContext";
|
||||||
|
import { GetUserResponse } from "@server/routers/user";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
type LandingProviderProps = {
|
type LandingProviderProps = {
|
||||||
user: boolean ;
|
user: GetUserResponse;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue