Authentication with the extension
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
export async function signOut() {
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user