supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

TypeError: supabaseClient.auth.signIn is not a function #526

Closed phongplus closed 1 year ago

phongplus commented 1 year ago

Supabase client

import { createClient } from '@supabase/supabase-js';

const supabaseUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}`;
const supabaseAnonKey = `${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY}`;

export const supabase = createClient(supabaseUrl, supabaseAnonKey);
const handleLogin = async () => {
    const { error: signInError } = await supabaseClient.auth?.signIn(
      {
        email: 'demo@gmail.com',
        password: '123456789'
      },
      { redirectTo: '/' }
    );
    console.log(signInError);
  };

dependencies

"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0"
"@supabase/supabase-js": "^2.0.0-rc.6",
"@supabase/ui": "^0.36.5",

is supabase support react 18 ?

soedirgo commented 1 year ago

I think you need to call a different method in v2: https://supabase.com/docs/reference/javascript/next/auth-signinwithpassword

phongplus commented 1 year ago

Thanks for @soedirgo It work, so any version or package of supabase auth ui working with v2 ? i try using @supabase/ui and supabase-community/auth-ui-react also not supported.

soedirgo commented 1 year ago

I'm not familiar with these libraries, but I'm guessing they're still on v1. I suggest creating an issue on these libs to use supabase-js v2, though we need to move supabase-js out of prerelease first.

strangecarr commented 1 year ago

Hi, any update on this? I'm trying Auth with Next and Typescript and getting errors such as: supabase.auth.signIn is not a function and supabase.auth.session is not a function

soedirgo commented 1 year ago

Yes, you need to follow the migration notes here, though you may not be able to use auth-helpers, auth-ui, etc. atm since they're using supabase-js v1.

strangecarr commented 1 year ago

thanks, that helped.

In UserContext.tsx I have:

return () => {
  authListener?.unsubscribe()
}
// eslint-disable-next-line react-hooks/exhaustive-deps

}, [])

VS Code is throwing: Property 'unsubscribe' does not exist on type '{ subscription: Subscription; }'.

I couldn't see anything in migration notes on this, are you able to suggest how to resolve please?

soedirgo commented 1 year ago

Maybe authListener?.subscription.unsubscribe()?

strangecarr commented 1 year ago

thanks, also helpful! Thinking I sholud've stuck with working in React and js - but sorry one last request - I've refactored session() to getSession(), but having trouble setting session in userContext as getSession returns a promise so VS code throws an error and the app doesn' recognise if the user is logged in:

const [session, setSession] = useState<Session | null>( supabaseClient.auth.getSession()

)

soedirgo commented 1 year ago

Hmm I'm not familiar with React myself - cc @alaister

alaister commented 1 year ago

@strangecarr it might be worth checking out this section of the next.js guide in the supabase docs, as it's got a good example of storing the session in state, which you should be able to apply to your user context.

Hope it helps!

strangecarr commented 1 year ago

thanks a lot, yes got it working now. Main issue was me getting v1 and v2 mixed up. Thanks for your help!

pratik-chakravorty commented 1 year ago

Similar to this is the supabase.auth.user() also different now. I get a similar not function error.

soedirgo commented 1 year ago

Closing this as OP's issue is resolved. Please follow the migration notes linked above for other obsoleted methods.

Hamza-Zahir commented 1 year ago

change signIn function with signInWithPassword