https://supabase.com/ logo
I'm using Sveltekit-auth-helper with redirect to h...
# help
a
I'm using Sveltekit-auth-helper with redirect to handle user invites. I have set the redirect URL in the Supabase dashboard, but the redirect, after confirmation, is still to the index route. I'm obviously missing something but I can't figure out what.
n
Hello @AlanK! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
s
Can you provide more information please? an example of the code you are using would be helpful.
a
I have a form component in a Modal with
Copy code
<form action="/auth/signup" method="post">
/auth/signup.js is
Copy code
import { supabaseClient } from '$lib/dbClient';

export async function POST({ request }) {
    const data = await request.formData();
    const email = data.get('email');
    const password = data.get('password');
    const headers = { location: '../survey' };
    const errors = {};
    const values = { email, password };

    const { user, error } = await supabaseClient.auth.signUp(
        {
            email: email,
            password: password
        },
        { redirectTo: '../survey' }
    );

    if (error) {
        errors.form = error.message;
        return {
            status: 400,
            body: {
                errors,
                values
            }
        };
    }
    const response = await fetch('http://127.0.0.1:5173/api/auth/callback', {
        method: 'POST',
        headers: new Headers({ 'Content-Type': 'application/json' }),
        credentials: 'same-origin',
        body: JSON.stringify({ event: 'SIGNED_UP', user })
    });
    return {
        status: 303,
        headers
    };
}
Site URL is http://127.0.0.1:5173/survey Redirect URLs is http://127.0.0.1:5173/survey When I respond to the Confirm email I get redirected to http://127.0.0.1:5173/#
s
Your redirectTo need to be the full URL not just a path
Also I'm not sure what this bit is doing in your code as there is no
SIGNED_UP
event that gets caught in the callback handler
Copy code
js
const response = await fetch('http://127.0.0.1:5173/api/auth/callback', {
        method: 'POST',
        headers: new Headers({ 'Content-Type': 'application/json' }),
        credentials: 'same-origin',
        body: JSON.stringify({ event: 'SIGNED_UP', user })
});
Do note I only use that hack on signing in on the server side in the email and password example.
a
Thank you for the clarification - I do feel a bit like a blind person in a dark room when it comes to this Auth stuff.
Okay, now that I know how the Redirect URLs work, thanks to @silentworks, I have been able to redirect to other pages on the site but not the one I want. I suspect there is a rogue redirect coming from the target page...
n
Thread was archived by @AlanK. Anyone can send a message to unarchive it.
2 Views