supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.02k stars 201 forks source link

Auth helper .signInWithPassword returns 401 unauthorized in Local Environment / CLI #962

Closed riccardolardi closed 5 months ago

riccardolardi commented 1 year ago

I'm getting POST http://localhost:54321/auth/v1/token?grant_type=password 401 (Unauthorized) when using signInWithPassword() in a local environment using Supabase CLI. It works in remote Supabase though.

The fetch/XHR payload is: { "email": "test", "password": "test", "gotrue_meta_security": {} }

The request URL is http://localhost:3000/#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjc5ODQ2Njg5LCJzdWIiOiIzOGE4MTJjMi02MzIzLTRkZGQtYjlmYi0yNTk2ZDI3N2I3NGUiLCJlbWFpbCI6InJpY2NhcmRvLmxhcmRpQGdtYWlsLmNvbSIsInBob25lIjoiIiwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1haWwiLCJwcm92aWRlcnMiOlsiZW1haWwiXX0sInVzZXJfbWV0YWRhdGEiOnt9LCJyb2xlIjoiYXV0aGVudGljYXRlZCIsImFhbCI6ImFhbDEiLCJhbXIiOlt7Im1ldGhvZCI6Im90cCIsInRpbWVzdGFtcCI6MTY3OTg0MzA4OX1dLCJzZXNzaW9uX2lkIjoiOTNhMzM3YWQtOWZmMy00NGY4LTgxM2EtODFkN2NlNGU1ZDI2In0.tGE5qIs86KwwQhGYoYOVzT8Cw3JapcN5fw7ZTD16h8k&expires_in=3600&refresh_token=0yt9L4RXtDyLBWmjF2MZBw&token_type=bearer&type=invite

Any clue why this happens?

sweatybridge commented 5 months ago

Closing this issue due to staleness as I can't reproduce locally.

import { createClient } from "npm:@supabase/supabase-js@2.42.0";

const supabase = createClient(
  "http://127.0.0.1:54321",
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0",
);

const { data, error } = await supabase.auth.signInWithPassword({
  email: "example@email.com",
  password: "example-password",
});

if (error) console.error(error);
console.dir(data, { depth: 5 });

If you are still running into this issue, perhaps double check the auth settings in config.toml, or run supabase init --force to refresh the config.