https://supabase.com/ logo
Join Discord
Powered by
# javascript
  • g

    GHOST

    09/08/2021, 7:05 PM
    Because signIn isn't well designed for external providers you can't await it, what I had to do was in like my global js file (I use svelte + routify so it's App.svelte for me) you have:
    Copy code
    js
        supabase.auth.onAuthStateChange((event, session) => {
            const data = session?.user;
    
            switch (event) {
                case 'SIGNED_IN':
                    // Set user as signed in, data is the user data
                    break;
                case 'SIGNED_OUT':
                    // Set user as signed out
                    break;
            }
        });
    Then in your login function you have
    Copy code
    js
    const signIn = () =>
        supabase.auth.signIn(
            {
                provider: 'discord',
            }
        );
    basically what happens is you call the signIn with discord which redirects to discord, when the user is redirected back to your app supabase should catch that and emit the event and you can respond to that hopefully they improve the design in the next version of supabase-js to have a popup meaning you would be able to do what they say in the docs for email and password the await supabase ... will work
  • g

    GHOST

    09/08/2021, 7:05 PM
    https://discord.com/channels/839993398554656828/869406062036529193/885239318808002580
  • y

    ymahmo

    09/08/2021, 7:45 PM
    Similar. Im using phone auth and get null for the user when I log in. Its been a little frustrating but hoping theres a fix for it soon, I saw some issues open on he github repo too
  • s

    stibbs

    09/08/2021, 8:41 PM
    @GHOST you can
    await
    sign in with external providers though
  • s

    stibbs

    09/08/2021, 8:43 PM
    https://github.com/ashleyconnor/sveltekit-supabase-demo
  • s

    stibbs

    09/08/2021, 8:49 PM
    That has a good example of hooking it all together with sveltekit
  • k

    Kylar

    09/08/2021, 9:10 PM
    How can I restore an auth session on NextJS' "getServerSideProps"? Is there a way to dump the session to a cookie and recover it from there?
    • 1
    • 1
  • g

    GHOST

    09/08/2021, 9:15 PM
    When you use a external provider you get redirected to that providers site, supabase js doesn't open that in a popup or a new tab it just redirects so your await would get aborted which is why you have to do it like I said The await system works perfect with email and password, it doesn't work with external providers
  • s

    stibbs

    09/08/2021, 9:22 PM
    Have you tried it? I’m using it without issue
  • s

    stibbs

    09/08/2021, 9:23 PM
    The onAuthStateChange also needs to be async(event, session). Check the link above, it has it all working and explains the flaws
  • s

    stibbs

    09/08/2021, 9:24 PM
    The signIn call hands off to supabase, and awaits a response from supabase - not directly from the external provider
  • s

    stibbs

    09/08/2021, 9:25 PM
    Is your callback url in the supabase auth settings ui correct? Is your supabase callback url with your external provider correct?
  • s

    Scott P

    09/09/2021, 1:04 AM
    This is correct. The flow of auth is: - [User] Attempts to sign in - [Supabase] Routes the request to the third-party provider - redirects the user to the provider auth page - [User] Confirms they wish to sign in to your service, using that provider as a source of truth for user data - [Third party provider] Processes the request, and redirects back to Supabase (providing the tokens used to authenticate and validate the request) - **[Supabase] **Adds the user details to the database, and redirects the user to the
    redirect_uri
    provided in the dashboard From there, it is up to the code on how it proceeds. If the user has already authed previously with that same provider, Supabase won't direct the user to auth again unless the third party provider requires it (e.g. if the user has removed that applications access from the account they have with the third party provider)
  • d

    Deleted User

    09/09/2021, 2:47 AM
    Hello, is it not possible to use
    .throwOnError()
    this way? I'm using this:
    Copy code
    js
    const { data: supabaseData } = await supabase
      .from('cases')
      .select('caseNumber')
      .order('caseNumber', { ascending: false })
      .limit(1)
      .single()
      .throwOnError();
    and it errors on
    throwOnError()
    saying
    Copy code
    js
    Property 'throwOnError' does not exist on type 'PromiseLike<PostgrestSingleResponse<any>>'.ts(2339)
    I'm also using Typescript. Thanks in advance
  • s

    Scott P

    09/09/2021, 3:00 AM
    throwOnError only seems to exist within the postgrest-js library, and not directly within the supabase-js library. You should be able to
    .catch()
    on the end, and throw the error that way if you need to. Alternatively, checking if errors is truthy and throwing that way is another option.
  • d

    Deleted User

    09/09/2021, 3:02 AM
    Oh ok, thanks
  • d

    davlaha

    09/09/2021, 5:10 PM
    Does anyone know how to get a refresh token using
    google oauth
    the documentation seems to be limited here
  • s

    stibbs

    09/10/2021, 2:26 AM
    Is https://github.com/ashleyconnor/sveltekit-supabase-demo still the "best" supabase auth implementation for a sveltekit project that needs auth w/ their endpoints?
  • s

    stibbs

    09/10/2021, 4:05 AM
    ^ that doesn't actually work anymore on sveltekit next.159... weird
  • n

    Neucoas

    09/10/2021, 12:52 PM
    I am on a point where I need to build some complex queries for a search/filter page on my app, where the supabase client nor a postgres functions suits the needs. I was thinking of connecting myself manually with a nodejs posgres library. Does anyone have recommendations other than
    pg
    ?
    s
    • 2
    • 3
  • a

    akaban

    09/10/2021, 2:26 PM
    Hello, I'm trying to understand how does the supabase-js library works, it seems like to me that the query building methods return a
    PostgresFilterBuilder
    object that contains all of the information of the request but the actual request will only be made when I await for this object. This is maybe a javascript classic thing to do but it seems strange that I have an object that can also behaves like a promise when we await. Can someone show me an example of supabase request without
    await
    ? This could help me understand I think, thanks a lot !
    j
    s
    • 3
    • 6
  • j

    jcarenza

    09/10/2021, 2:37 PM
    async/await is just traditional promises under the hood. you should be able to use it as a normal promise if you choose not to use
    await
    like:
    supabase.auth.signIn().then()
  • a

    akaban

    09/10/2021, 2:43 PM
    Ok I see perfect, I just need to give it an empty
    then
    and it works. Thanks a lot ! JS-related question, does that mean that the real supabase promise in only fired when we call then on it?
  • s

    Scott P

    09/10/2021, 2:47 PM
    The request is probably sent when you call
    .signIn()
    , but you won't receive the response back in your code, as it's not something that runs in sync. It's fairly common for code which should be run as async/a promise to return an object if you
    console.log()
    it, unless you
    await
    or
    .then()
    it. Remember, that the primitive types in JS are string, number, bigint, boolean, symbol, null and undefined. Everything else is an object (even arrays).
  • j

    jcarenza

    09/10/2021, 2:48 PM
    @User perhaps this would be helpful for you regarding using promises: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises
  • a

    akaban

    09/10/2021, 2:49 PM
    I see thanks, for the information when I tried to use
    insert
    and not
    signin
    the real insert would only happen when I would await for the
    PostgresFilterBuilder
    so it looks like the request is not fired without awaiting
  • a

    akaban

    09/10/2021, 2:49 PM
    I kinda read that already but I have to say that I hate the promise paradigm šŸ˜†
  • s

    Scott P

    09/10/2021, 2:50 PM
    JS - Promises and Async
  • s

    Scott P

    09/10/2021, 2:50 PM
    I've made a thread to discuss further - let's move there šŸ™‚
  • s

    Subh

    09/10/2021, 5:54 PM
    How do we reset password for phone auth?
1...171819...81Latest