Coder Social home page Coder Social logo

Update user data about supabase-js HOT 15 CLOSED

supabase avatar supabase commented on June 17, 2024
Update user data

from supabase-js.

Comments (15)

tconroy avatar tconroy commented on June 17, 2024 3

Now that it's 2021, curious what the preferred solution is.

there is

await supabase.auth.update({
  data: {
    email: '[email protected]'
  },
});

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.

from supabase-js.

zlwaterfield avatar zlwaterfield commented on June 17, 2024 2

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,
      },
    });
  }

from supabase-js.

kiwicopple avatar kiwicopple commented on June 17, 2024 2

Also a note that we will be adding this to supabase-js - we are revising the auth API now

from supabase-js.

thorwebdev avatar thorwebdev commented on June 17, 2024 2

@tconroy for email it's const { user, error } = await supabase.auth.update({email: '[email protected]'})

This will send an email to both the user's current and new email with a confirmation link.

from supabase-js.

rommyarb avatar rommyarb commented on June 17, 2024 2

It's 2022, boys. Now you can do these:

  • On server (with service_role key):
await supabase.auth.api.updateUserById(userId, { email: '[email protected]' })
  • On client / browser, with JWT:
await supabase.auth.api.updateUser(userJwt, { email: '[email protected]' })

from supabase-js.

ankushg avatar ankushg commented on June 17, 2024 2

@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?

from supabase-js.

tiagopaespride avatar tiagopaespride commented on June 17, 2024 2

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();

from supabase-js.

hansy avatar hansy commented on June 17, 2024 1

@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.

from supabase-js.

AwesomeZaidi avatar AwesomeZaidi commented on June 17, 2024 1

Once this update happens on the client, if im updating metadata, the user object in session doesn't reflect the change

from supabase-js.

leocastroz avatar leocastroz commented on June 17, 2024 1

In vue.js 3

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!!
br

from supabase-js.

zlwaterfield avatar zlwaterfield commented on June 17, 2024

Awesome thanks, I'll take a look.

from supabase-js.

kiwicopple avatar kiwicopple commented on June 17, 2024

thanks for pitching in here @hansy

from supabase-js.

raimille1 avatar raimille1 commented on June 17, 2024

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
  },
})

from supabase-js.

thorwebdev avatar thorwebdev commented on June 17, 2024

You can update a logged in user client-side by calling: supabase.auth.updateUser: https://supabase.com/docs/reference/javascript/auth-updateuser

from supabase-js.

aldrinjenson avatar aldrinjenson commented on June 17, 2024

@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: '[email protected]' });

from supabase-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.