0
Authenticate with email and password
One script reply has been approved by the moderators Verified
Created by adam186 388 days ago Viewed 5407 times
0
Submitted by adam186 Deno
Verified 388 days ago
1
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.10.0";
2

3
type Supabase = {
4
  url: string;
5
  key: string;
6
};
7
export async function main(auth: Supabase, email: string, password: string) {
8
  const client = createClient(auth.url, auth.key);
9
  const { data, error } = await client.auth.signInWithPassword({
10
    email,
11
    password,
12
  });
13
  if (error) {
14
    return {
15
      access_token: undefined,
16
      refresh_token: undefined,
17
      error: error.message,
18
    };
19
  }
20
  return {
21
    access_token: data?.session?.access_token,
22
    refresh_token: data?.session?.refresh_token,
23
    error: undefined,
24
  };
25
}
26