mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-02 16:56:39 +00:00
Fix login stuff?
This commit is contained in:
@@ -2,8 +2,8 @@ import LoginForm from "@app/components/LoginForm";
|
||||
import { verifySession } from "@app/lib/verifySession";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function Page() {
|
||||
const { user } = await verifySession();
|
||||
export default async function Page() {
|
||||
const user = await verifySession();
|
||||
|
||||
if (user) {
|
||||
redirect("/");
|
||||
@@ -15,6 +15,3 @@ export async function Page() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Page;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LandingProvider } from "@app/providers/LandingProvider";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
const { user } = await verifySession();
|
||||
const user = await verifySession();
|
||||
|
||||
if (!user) {
|
||||
redirect("/auth/login");
|
||||
@@ -12,7 +12,7 @@ export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<LandingProvider user={user}>
|
||||
<p>You're logged in!</p>
|
||||
<p>You are logged in!</p>
|
||||
</LandingProvider>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
|
||||
import { LoginResponse } from "@server/routers/auth";
|
||||
import { api } from "@app/api";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
type LoginFormProps = {
|
||||
redirect?: string;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
export const UserContext = createContext<{ id: string } | null>(null);
|
||||
export const UserContext = createContext<boolean | null>(null);
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
import api from "@app/api";
|
||||
import { cookies } from "next/headers";
|
||||
import lucia from "@server/auth";
|
||||
|
||||
export async function verifySession() {
|
||||
const sessionId = cookies().get(lucia.sessionCookieName)?.value ?? null;
|
||||
const session = await lucia.validateSession(sessionId || "");
|
||||
return session;
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
|
||||
try {
|
||||
const res = await api.get("/user", {
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { UserContext } from "@app/contexts/userContext";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
type LandingProviderProps = {
|
||||
user: any;
|
||||
user: boolean ;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user