Authenticate with email and password

Script supabase Verified

by adam186 ยท 3/27/2023

The script

Submitted by hugo989 Bun
Verified 3 days ago
1
import { createClient } from "@supabase/[email protected]"
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

Other submissions
  • Submitted by adam186 Deno
    Created 395 days ago
    1
    import { createClient } from "https://esm.sh/@supabase/[email protected]";
    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