Skip to content

Commit 1762f5c

Browse files
committed
make logout a client-side action
1 parent e4bb368 commit 1762f5c

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

autogpt_platform/frontend/src/lib/supabase/actions.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

autogpt_platform/frontend/src/lib/supabase/useSupabase.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use client";
22
import { useCallback, useEffect, useMemo, useState } from "react";
33
import { createBrowserClient } from "@supabase/ssr";
4-
import { User } from "@supabase/supabase-js";
5-
6-
import { _logoutServer } from "./actions";
4+
import { SignOut, User } from "@supabase/supabase-js";
5+
import { useRouter } from "next/navigation";
76

87
export default function useSupabase() {
8+
const router = useRouter();
99
const [user, setUser] = useState<User | null>(null);
1010
const [isUserLoading, setIsUserLoading] = useState(true);
1111

@@ -42,8 +42,17 @@ export default function useSupabase() {
4242
}, [supabase]);
4343

4444
const logOut = useCallback(
45-
() => Promise.all([_logoutServer(), supabase?.auth.signOut()]),
46-
[supabase],
45+
async (options?: SignOut) => {
46+
if (!supabase) return;
47+
48+
const { error } = await supabase.auth.signOut({
49+
scope: options?.scope ?? "local",
50+
});
51+
if (error) console.error("Error logging out:", error);
52+
53+
router.push("/login");
54+
},
55+
[router, supabase],
4756
);
4857

4958
if (!supabase || isUserLoading) {

0 commit comments

Comments
 (0)