Fix login stuff?

This commit is contained in:
Owen Schwartz
2024-10-06 18:43:20 -04:00
parent 06eb1544f4
commit d144704066
11 changed files with 76 additions and 37 deletions

View File

@@ -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;

View File

@@ -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>
</>
);

View File

@@ -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;

View File

@@ -1,3 +1,3 @@
import { createContext } from "react";
export const UserContext = createContext<{ id: string } | null>(null);
export const UserContext = createContext<boolean | null>(null);

View File

@@ -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
}
}

View File

@@ -4,7 +4,7 @@ import { UserContext } from "@app/contexts/userContext";
import { ReactNode } from "react";
type LandingProviderProps = {
user: any;
user: boolean ;
children: ReactNode;
};