Is there an way to login to a user on the server side without sending the token to the client?
Hi, is there an way to login to a user on the server side without sending the token to the client? Because I have a form for unlogged in user and if they submit the form and the sever insert the data the user gets a jwt token. I added useSsrCookies: false to the Nuxt.config.ts and it didn't worked.
Best regards.
If you're asking to be able to "impersonate" a login as another user, this is how I do it.
I first guard so admins can't be impersonated, and admins are defined via user_metadata.role
user.user_metadata?.role === 'admin'
I have another callback page for impersonation specifically to give more details as the process takes a little longer as it's more calls.
const redirectUrl = import.meta.dev
? 'http://localhost:3000/admin/impersonate-callback'
: `${config.public.siteUrl || config.public.supabase.url}/admin/impersonate-callback`;
Then I create a magic link. You likely need that auth method enabled. I would assume so, but I never tried with it off.
const { data: linkData, error: linkError } = await serviceRole.auth.admin.generateLink({
type: 'magiclink',
email: targetUser.user.email!,
options: {
redirectTo: redirectUrl,
},
});
I also return the data from the api to complete the call
return {
success: true,
magicLink: linkData.properties?.action_link,
targetUser: {
id: targetUser.user.id,
email: targetUser.user.email,
full_name: targetUser.user.user_metadata?.full_name,
},
adminUserId: adminUser.id,
};
That's essentially it.