Closed zlwaterfield closed 3 years ago
@zlwaterfield Check out Issue #21. In short, you can update user info by directly sending a request to your supabase endpoint. Supabase is using Netlify's GoTrue API to power authentication so you should be able to call any endpoint listed there using your unique supabase url and API key.
Awesome thanks, I'll take a look.
thanks for pitching in here @hansy
For anyone else coming here, here is an example snippet to help:
async changeEmail(email) {
return await axios({
method: 'PUT',
url: `${SupabaseService.auth.authUrl}/user`,
headers: {
authorization: `Bearer ${SupabaseService.auth.accessToken}`,
apikey: SupabaseService.auth.supabaseKey,
},
data: {
email,
},
});
}
Also a note that we will be adding this to supabase-js - we are revising the auth API now
Now that it's 2021, curious what the preferred solution is.
there is
await supabase.auth.update({
data: {
email: 'foo@bar.com'
},
});
however, this doesn't seem to correlate with the users.email
column.
Also, not clear how to re-trigger a confirmation email on email change.
@tconroy for email it's const { user, error } = await supabase.auth.update({email: 'new@email.com'})
This will send an email to both the user's current and new email with a confirmation link.
Any idea on how to restrict updates to that column for specific values?
// I want to throw an error for when a user does this, but let them update anything else
await supabase.auth.update({
data: {
read_only_property: true
},
})
It's 2022, boys. Now you can do these:
On server (with service_role key):
await supabase.auth.api.updateUserById(userId, { email: 'foo@bar.com' })
On client / browser, with JWT:
await supabase.auth.api.updateUser(userJwt, { email: 'foo@bar.com' })
@rommyarb it's still 2022, but it looks like the supabase.auth.api.updateUser
method doesn't exist anymore in version 2.0+ :(
Is there an updated way to do this client-side with JWT?
You can update a logged in user client-side by calling: supabase.auth.updateUser
: https://supabase.com/docs/reference/javascript/auth-updateuser
Once this update happens on the client, if im updating metadata, the user object in session doesn't reflect the change
Once this update happens on the client, if im updating metadata, the user object in session doesn't reflect the change
I had the same problem. It works if you refreshes the session after updating the user data.
await supabase.auth.refreshSession();
@rommyarb it's still 2022, but it looks like the supabase.auth.api.updateUser method doesn't exist anymore in version 2.0+ :(
Hey, this can now be done from server side using this API: supabase.auth.admin.updateUserById(userId, { email: 'foo@bar.com' });
import { supabase } from "@/clients/supabase";
const updateFirstName = async () => {
try {
const { data, error } = await supabase.auth.admin.updateUserById(userId, {
user_metadata: { first_name: firstName.value }
})
if (error) {
console.error('Error updating first name:', error);
} else {
console.log('First name updated successfully:', data);
}
} catch (error) {
console.error('Error updating first name:', error);
}
}
Let's go up Brazil!!
Question
How can you update user data? Here are the possibilities I see:
user_metadata
but don't see a way to update it.user
and join on the UID the signup generates. If that is the case how can we create a foreign key to the auth'd user row?