37 lines
966 B
TypeScript
37 lines
966 B
TypeScript
"use client"; // must run in the browser
|
|
import { createBrowserClient } from "@supabase/ssr";
|
|
|
|
export const supaBrowser = createBrowserClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
);
|
|
|
|
export async function signInWithGoogle(
|
|
redirectTo = `${window.location.origin}/auth/callback`,
|
|
) {
|
|
const { error, data } = await supaBrowser.auth.signInWithOAuth({
|
|
provider: "google",
|
|
options: { redirectTo },
|
|
});
|
|
|
|
if (error) throw error;
|
|
|
|
// the page will redirect automatically; data is only for tests
|
|
return data;
|
|
}
|
|
|
|
export async function signOut() {
|
|
const { error } = await supaBrowser.auth.signOut();
|
|
if (error) throw error;
|
|
}
|
|
|
|
/**
|
|
* Cleans the module-content bucket by removing all files.
|
|
* Only use during development.
|
|
*/
|
|
export async function emptyBucket() {
|
|
const { data, error } = await supaBrowser.storage.emptyBucket('module-content');
|
|
if (error) throw error;
|
|
return data;
|
|
}
|