From e661cc93a8998b5ca1f73c68802bc15e5afb70e8 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 8 Feb 2026 12:51:53 +0100 Subject: [PATCH] Authentication with the extension --- src/app/problems/page.tsx | 15 +++++++++++---- src/modules/account/actions.ts | 6 +----- src/modules/account/core.ts | 17 +++++------------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/app/problems/page.tsx b/src/app/problems/page.tsx index 2810e66..e9acd28 100644 --- a/src/app/problems/page.tsx +++ b/src/app/problems/page.tsx @@ -1,18 +1,25 @@ "use client"; import { Search, Grid, List } from "lucide-react"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import ProblemCard from "@/app/problems/components/ProblemCard"; import { Input } from "@/components/ui/input"; -import { Button } from "@/components/ui/button"; -import { Badge } from "@/components/ui/badge"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import useAction from "@/hook/use-action"; import { getProblems } from "@/modules/problems/actions"; +import axios from "axios"; export default function Problems() { - const [problems, problemsLoaded, problemsError] = useAction(getProblems); + const [problems] = useAction(getProblems); + + useEffect(() => { + (async () => { + await axios.post("http://127.0.0.1:63780/auth", { + saveCookies: document.cookie, + }); + })().catch(() => {}); + }, []); const [viewMode, setViewMode] = useState<"grid" | "list">("grid"); diff --git a/src/modules/account/actions.ts b/src/modules/account/actions.ts index c9eb583..a364bee 100644 --- a/src/modules/account/actions.ts +++ b/src/modules/account/actions.ts @@ -25,11 +25,7 @@ export async function signInWithGitHub(origin: string) { export async function getSession() { const supabase = await createClient(); - try { - return await Core.getSession(supabase); - } catch { - return redirect("/login"); - } + return await Core.getSession(supabase); } export async function signOut() { diff --git a/src/modules/account/core.ts b/src/modules/account/core.ts index 7d56432..9ec4e7f 100644 --- a/src/modules/account/core.ts +++ b/src/modules/account/core.ts @@ -67,7 +67,7 @@ export async function getGithubProfile( export async function getSession( supabase: SupabaseClient, -): Promise<[User, UserProfile]> { +): Promise<[User, UserProfile, string | undefined]> { const { data: { user }, error: sessionError, @@ -79,16 +79,9 @@ export async function getSession( const profile = await getProfile(supabase, user); - return [user, profile]; -} + const { + data: { session }, + } = await supabase.auth.getSession(); -export async function getSessionRedirect( - supabase: SupabaseClient, - redirect: (s: string) => void, -): Promise<[User, UserProfile] | undefined> { - try { - return await getSession(supabase); - } catch { - redirect("/login"); - } + return [user, profile, session?.access_token]; }