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

    burggraf

    07/28/2021, 2:58 PM
    It's a good idea, maybe add a request in the PostgREST github page.
  • u

    user

    07/28/2021, 5:22 PM
    Hey, this indeed does work. This is the method I was trying before actually, however I did not notice the 'confirm' email!
  • b

    burggraf

    07/28/2021, 5:46 PM
    Thanks for confirming this! I appreciate it!
  • u

    user

    07/28/2021, 5:47 PM
    No worries, I'm not sure why it isn't in the main docs so I have opened a PR.
  • u

    user

    07/28/2021, 5:50 PM
    @User - some more info on this link, as I am now working to "do something" with the confirmation email in my app - https://supabase.io/docs/gotrue/client/api-updateuser
  • l

    laznic

    07/28/2021, 6:02 PM
    Just out of curiosity: how many of you are using Supabase in an SPA?
  • s

    stibbs

    07/29/2021, 12:29 AM
    Any suggestions on this? 🙂
  • s

    stibbs

    07/29/2021, 12:34 AM
    Am I better off using
    supabase.auth.api.setAuthCookie
    and
    supabase.auth.api.getUserByCookie
    ?
  • f

    frubalu

    07/29/2021, 2:32 AM
    This is kind of where I’m at too. I’m needing to store the access token in a cookie to use in further requests after the user is logged in. Take a look at this article, it’s what I’ve been going off of lately: https://dev.to/dabit3/magic-link-authentication-and-route-controls-with-supabase-and-next-js-leo
  • f

    frubalu

    07/29/2021, 2:34 AM
    Basically you create a ‘/api/auth’ route (not sure if you’re using NextJS), which sets the cookie server-side, then on the client side you can use ‘getUserByCookie’
  • s

    stibbs

    07/29/2021, 4:30 AM
    Thanks I'll give it a go 🙂
  • f

    frubalu

    07/29/2021, 4:37 AM
    Let me know if you have any questions!
  • s

    stibbs

    07/29/2021, 4:39 AM
    I think I'm doing it wrong....
  • s

    stibbs

    07/29/2021, 4:49 AM
    Copy code
    const { user } = await supabase.auth.api.getUserByCookie(req.headers.token);
    const { data, error } = await getSettings(user.id);
    user.id is always null?
  • f

    Flyken

    07/29/2021, 4:50 AM
    Copy code
    js
    if(users){
      console.log(user)
    }
    have you tried something like this? just in case
  • s

    stibbs

    07/29/2021, 4:52 AM
    Ah I think my fetcher is broken... getting 500 error
  • f

    Flyken

    07/29/2021, 4:52 AM
    that'll dew et
  • a

    Azura

    07/29/2021, 4:52 AM
    500 error is internal server error. Could you contact support by using the Feedback widget in your Supabase dashboard? @User
  • s

    stibbs

    07/29/2021, 4:53 AM
    Supabase* 😉
  • a

    Azura

    07/29/2021, 4:53 AM
    Fixed. haha
  • s

    stibbs

    07/29/2021, 4:53 AM
    It's probably my code first though... I'm confusing so many things here
  • f

    Flyken

    07/29/2021, 4:54 AM
    yea, i got some 500 errors and it wans't supabase
  • s

    stibbs

    07/29/2021, 5:00 AM
    Ok... The call from /pages/account
    Copy code
    const { user, session } = useUser();
      const { data, error } = useSWR(
        user ? ['/api/settings', session.access_token] : null,
        fetcher
      );
    fetcher
    Copy code
    export const fetcher = (url, token) => {
      return fetch(url, {
        method: 'GET',
        headers: new Headers({ 'Content-Type': 'application/json', token }),
        credentials: 'same-origin'
      }).then((res) => {
        return res.json();
      });
    };
    /pages/api/auth
    Copy code
    import type { NextApiRequest, NextApiResponse } from 'next';
    import supabase from '@utils/supabase';
    
    const handler = async (
      req: NextApiRequest,
      res: NextApiResponse
    ): Promise<void> => {
      supabase.auth.api.setAuthCookie(req, res);
    };
    
    export default handler;
  • s

    stibbs

    07/29/2021, 5:07 AM
    So the SWR call itself is failing and never running the settings api
  • s

    stibbs

    07/29/2021, 5:08 AM
    Session token definitely exists
  • s

    stibbs

    07/29/2021, 5:09 AM
    One thing is for sure, the fact i've gotten this far is a testament to supabase 🤣
  • u

    user

    07/29/2021, 5:11 AM
    Might need to return a response from the auth handler? Try adding
    res.status(200).end()
    at the end of your handler
  • u

    user

    07/29/2021, 5:11 AM
    @User ^
  • s

    stibbs

    07/29/2021, 5:18 AM
    Hmm that didn't fix it but you are probably right - I stole that code from https://github.com/dabit3/supabase-nextjs-auth
  • s

    stibbs

    07/29/2021, 5:22 AM
    const { user } = await supabase.auth.api.getUserByCookie(req.headers.token);
    returns null
12345...81Latest