supabase / auth

A JWT based API for managing users and issuing JWT tokens
https://supabase.com/docs/guides/auth
MIT License
1.53k stars 372 forks source link

user metadata with magic link #699

Closed rlee1990 closed 2 years ago

rlee1990 commented 2 years ago

It would be nice to allow for the ability to add user metadata when someone is using the magic link or to make a password option on the signup field to allow for magic links.

activenode commented 2 years ago

Could you please provide a very specific sample how you imagine this to be?

rlee1990 commented 2 years ago

Could you please provide a very specific sample how you imagine this to be?

So after some thought. To me the best approach would be to make the signup option to allow for passwords to be optional just like the signin option. That way if someone signs up for a site that also take things like username name and date of birth they can get past in with the raw user metadata. I don't see how much of a difference it would be vs having to provide a password or not.

activenode commented 2 years ago

I think the logic of both should be cleaned up anyways (see https://github.com/supabase/gotrue-js/issues/449 as well).

They do too much stuff implicitly. I also do think there should be a method such as signUpWithEmailWithoutPassword same as the gotrue one signUpWithEmail which already exists but then without a password which would be more meaningful than signIn which implicitly registers a user which is very weird to me honestly.

chrisb2244 commented 2 years ago

My workaround here was to generate a random password for the user, and never tell them what it is (since I only offered magiclink signup/in). But of course, this is a strange behaviour for a non-obvious reason, and I'd prefer to see something like what's suggested above...

rlee1990 commented 2 years ago

@chrisb2244 That's what I was think as a workaround but that could have adverse effects down the line hopefully this will gain enough support

kangmingtay commented 2 years ago

hey everyone, closing this out because we've added this to gotrue already (https://github.com/supabase/gotrue/pull/506, https://github.com/supabase/gotrue/pull/658)

rlee1990 commented 2 years ago

hey everyone, closing this out because we've added this to gotrue already (https://github.com/supabase/gotrue/pull/506, https://github.com/supabase/gotrue/pull/658)

That's nice any clue when it might land on the flutter or dart package?

J0 commented 2 years ago

Hey @rlee1990,

Not too sure at the moment, but we're looping in the Flutter maintainer: @dshukertjr into the thread so that there's visibility on the feature.

dshukertjr commented 2 years ago

@rlee1990 Hopefully not too long from now! We are in the process of making the developer preview version of gotrue-dart to be aligned with gotrue-js rc right now!

rlee1990 commented 2 years ago

@dshukertjr is there any thing on github for us to follow for progress on this?

dshukertjr commented 2 years ago

@rlee1990 You can follow this PR!

dshukertjr commented 2 years ago

I just tried calling signInWithOtp with some metadata, and it seems like the metadata is not being saved on the server side. I wonder if it's a server side issue or a client side issue.

Code that I used:

    const { error } = await supabase.auth.signInWithOtp({
      email: 'my_new_email@gmail.com',
      options: {
        data: { name: 'something' },
      },
    })
kangmingtay commented 2 years ago

Yup, good catch @dshukertjr! I've made a PR in gotrue to fix this issue already, it should go out to all supabase projects next week.

One caveat though: If the user has already signed up, you can't use the data param to update the user_metadata field. The user will have to update it using the updateUser method in gotrue-js

rlee1990 commented 2 years ago

Yup, good catch @dshukertjr! I've made a PR in gotrue to fix this issue already, it should go out to all supabase projects next week.

One caveat though: If the user has already signed up, you can't use the data param to update the user_metadata field. The user will have to update it using the updateUser method in gotrue-js

Is there a pr or something I can follow so I now when this has been fixed?

thecodingpapa commented 1 year ago

Hi, It's been a while. and I have just tried to get the data via magic link and it seems the data does not go through. am I missing something??

I develop vite react ts.

    const { error } = await supabase.auth.signInWithOtp({ email:email, options: {data: {
      Title: "Вашият магически линк",
      H2: "Магически линк",
      P: "Следвайте този линк, за да влезете в профила си:",
      Link: "Влезте в профила си"
  }} });

in Email Templates

<h2>{{ .Data.H2 }}</h2>

<p>{{ .Data.P }}  {{ .Email }} {{ .Data.To }}  {{ .NewEmail }}:</p>
<p><a href="{{ .ConfirmationURL }}">{{ .Data.Link }}</a></p>

Thank you.

kangmingtay commented 1 year ago

Hi @thecodingpapa, that should work, but it seems like the data only goes through the first time a user is signed up. Subsequent signup attempts by the same user will only result in sending whatever data was sent the first time.

thecodingpapa commented 1 year ago

Hi @kangmingtay, Thank you for your prompt reply earlier. I have a follow-up question.

In the future, Will it be changed to the 'Data' to update dynamically when a user signs in, rather than just during sign-up? I am concerned that users may change their language preference after their initial sign-up, and this cause a mismatch between the language preference in my application and the language used in email notifications.

Thank you once again!