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

    Mihai Andrei

    12/20/2021, 9:26 AM
    I think you might have a bad link inside the createSupabase function
  • z

    Zenon

    12/20/2021, 12:33 PM
    Hey guys, I'm using Supabase Auth with Next.js This is what my API register function looks like...
    Copy code
    javascript
    export default async function handler(req, res) {
    
            const { username, email, password } = req.body;
    
            let { user, error } = await supabase.auth.signUp({
                email: email,
                password: password,
            });
    
            if (!error) {
                res.status(201).json({ data: user, message: "Signed Up!" });
            }
    }
    I want the user I get from the signUp function to be stored in a cookie so that I can get the user from cookie in a different endpoint using
    Copy code
    supabase.auth.api.getUserByCookie
  • r

    Romain Petit

    12/20/2021, 1:27 PM
    Hi, I think that before you return a 201 you can add this line:
    Copy code
    supabase.auth.api.setAuthCookie(req)
  • z

    Zenon

    12/20/2021, 2:28 PM
    I get this error
  • r

    Romain Petit

    12/20/2021, 2:30 PM
    You should add
    Copy code
    event: 'SIGNED_IN
    in the request body and probably the user too
  • z

    Zenon

    12/20/2021, 2:31 PM
    okay
  • z

    Zenon

    12/20/2021, 2:32 PM
    didn't get the second part I added 'event' to the request body
  • r

    Romain Petit

    12/20/2021, 2:34 PM
    In the request body you have to add the sign in event and and the user as a session like this and I think this should work
    Copy code
    { event: 'SIGNED_IN', session: user }
  • z

    Zenon

    12/20/2021, 2:35 PM
    Where do I get the user for the session
  • z

    Zenon

    12/20/2021, 2:35 PM
    Copy code
    javascript
    let user = {
                email: email,
                password: password,
                event: "SIGNED_IN",
            };
  • r

    Romain Petit

    12/20/2021, 2:35 PM
    From the sign in function
  • z

    Zenon

    12/20/2021, 2:37 PM
    I'm sorry could you demonstrate the code once? 😓
  • r

    Romain Petit

    12/20/2021, 2:38 PM
    No problem 🙂
    Copy code
    export default async function handler(req, res) {
    
        const { username, email, password } = req.body;
    
        let { user, error } = await supabase.auth.signUp({
            email: email,
            password: password,
        });
    
        if (!error) {
            req.body.event = 'SIGNED_IN'
            req.body.session = user;
    
            await supabase.auth.api.setAuthCookie(req, res)
            res.status(201).json({ data: user, message: "Signed Up!" });
        }
    }
  • z

    Zenon

    12/20/2021, 2:39 PM
    got it
  • r

    Romain Petit

    12/20/2021, 2:39 PM
    Is it working now ?
  • z

    Zenon

    12/20/2021, 2:42 PM
    😦
  • r

    Romain Petit

    12/20/2021, 2:44 PM
    Try by adding res as second parameter of the setAuthCookie function (i edited my previous message)
  • z

    Zenon

    12/20/2021, 2:45 PM
    Didn't get an error on the client side but I got this
  • z

    Zenon

    12/20/2021, 2:45 PM
    Copy code
    Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  • z

    Zenon

    12/20/2021, 2:45 PM
    on the server
  • r

    Romain Petit

    12/20/2021, 2:45 PM
    Arf I can't help you on the server side ..
  • z

    Zenon

    12/20/2021, 2:46 PM
    I see
  • z

    Zenon

    12/20/2021, 2:46 PM
    thanks man
  • t

    tdotflight22

    12/20/2021, 6:37 PM
    yeah im using a form
  • k

    krithika

    12/20/2021, 10:08 PM
    i'm trying to get signin/signup working in a project with React. On sign in, I'm getting an error saying "You must provide either an email, phone number or a third-party provider." when i enter in a valid email. My current code reads as the following for signin```javascript const signin = async (username, password, history) => { console.log("log in called", username, password) try { const {error} = await supabase.auth.signIn({username, password}) if (error) throw error alert('logged in') console.log('logged in') window.location.href = '/dashboard'; // history.push('/dashboard') } catch (error) { alert(error.message) } } ``` - would you know what's causing this error? (the console log is printing the expected output too). My code for signup is structured similarly, except it calls
    signUp
    instead. When signup is called, I'm getting no output in the console, and the page just reloads. Would you know what's causing that/how I could go about fixing/debugging this?
  • k

    krithika

    12/20/2021, 10:38 PM
    would i say something like
    const {access_token, error} = await supabase.auth.signIn({username, password})
    ?
  • s

    Scott P

    12/20/2021, 11:25 PM
    The property is
    email
    , not
    username
  • k

    krithika

    12/20/2021, 11:50 PM
    but that's just a case of variable names right? (changing username to email doesn't/shouldn't change anything)
  • s

    Scott P

    12/20/2021, 11:52 PM
    They're calling
    signIn({ username, password })
    and the error is telling them to provide a valid email, so changing that to
    signIn({ email: username, password })
    should fix it
  • k

    krithika

    12/20/2021, 11:57 PM
    thanks, that fixed it!
1...383940...81Latest