mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
32 lines
909 B
TypeScript
32 lines
909 B
TypeScript
import { getServerSupabase } from "./getServerSupabase";
|
|
|
|
export async function getServerUser() {
|
|
const supabase = await getServerSupabase();
|
|
|
|
if (!supabase) {
|
|
return { user: null, error: "Failed to create Supabase client" };
|
|
}
|
|
|
|
try {
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
// if (error) {
|
|
// // FIX: Suppressing error for now. Need to stop the nav bar calling this all the time
|
|
// // console.error("Supabase auth error:", error);
|
|
// return { user: null, role: null, error: `Auth error: ${error.message}` };
|
|
// }
|
|
if (!user) {
|
|
return { user: null, role: null, error: "No user found in the response" };
|
|
}
|
|
const role = user.role || null;
|
|
return { user, role, error: null };
|
|
} catch (error) {
|
|
return {
|
|
user: null,
|
|
role: null,
|
|
error: `Unexpected error: ${(error as Error).message}`,
|
|
};
|
|
}
|
|
}
|