Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supabase.auth.signUp() with metadata returns nil User, even if result successful #172

Closed
marcusraty opened this issue Dec 5, 2023 · 3 comments · Fixed by #174
Closed
Labels
bug Something isn't working

Comments

@marcusraty
Copy link

Bug report

supabase.auth.signUp()

Describe the bug

I was previously using supabase.auth.signUp() successfully, but have added a trigger to the auth table, I am sending metadata in supabase.auth.signUp() now and using this in my trigger. I have confirm email turned off.

supabase.auth.signUp() returns (ie does not throw an error). In my dashboard I can see the new user in my auth table, and I can see the new row in my public.profiles which was the result of my trigger.

Printing the result seems to show a User as well, unless I am mistaken! However when I attempt to unwrap this and get the user, it returns nil.

`result is session(GoTrue.Session(providerToken: nil, providerRefreshToken: nil, accessToken: REMOVED", tokenType: "bearer", expiresIn: 3600.0, refreshToken: "REMOVED", user: GoTrue.User(id: REMOVED, appMetadata: ["providers": _Helpers.AnyJSON.array([_Helpers.AnyJSON.string("email")]), "provider": _Helpers.AnyJSON.string("email")], userMetadata: ["isPublic": _Helpers.AnyJSON.bool(true), "username": _Helpers.AnyJSON.string("marcusroar"), "dateOfBirth": _Helpers.AnyJSON.string("2004-12-05")], aud: "authenticated", confirmationSentAt: nil, recoverySentAt: nil, emailChangeSentAt: nil, newEmail: nil, invitedAt: nil, actionLink: nil, email: Optional("REMOVED"), phone: Optional(""), createdAt: 2023-12-05 06:52:23 +0000, confirmedAt: nil, emailConfirmedAt: Optional(2023-12-05 06:52:23 +0000), phoneConfirmedAt: nil, lastSignInAt: Optional(2023-12-05 06:52:23 +0000), role: Optional("authenticated"), updatedAt: 2023-12-05 06:52:23 +0000, identities: Optional([GoTrue.UserIdentity(id: "df71ad62-ef45-4025-b2f6-282744d2938d", userId: DF71AD62-EF45-4025-B2F6-282744D2938D, identityData: Optional(["email": _Helpers.AnyJSON.string("[email protected]"), "email_verified": _Helpers.AnyJSON.bool(false), "sub": _Helpers.AnyJSON.string("df71ad62-ef45-4025-b2f6-282744d2938d"), "phone_verified": _Helpers.AnyJSON.bool(false)]), provider: "email", createdAt: 2023-12-05 06:52:23 +0000, lastSignInAt: 2023-12-05 06:52:23 +0000, updatedAt: 2023-12-05 06:52:23 +0000)]), factors: nil)))

`

Expected behavior

If supabase.auth.signUp() is successful both User and Session should be returned

Additional context

Happy to provide any additional details - thanks!

@marcusraty marcusraty added the bug Something isn't working label Dec 5, 2023
@grdsdev
Copy link
Collaborator

grdsdev commented Dec 5, 2023

Hey @marcusraty

From the print output you pasted, it contains a session and not a nil value as you mentioned.

The signUp method returns an AuthResponse type, this type is an enum that could contain a whole Session or just a User. The returned type will depend on your project configuration, if it is configured to require email confirmation after a sign up, then signUp method will return a User, and not a session because it requires confirmation, it returns a Session otherwise.

Here is an example on how you should use it:

let response = try await client.signUp(email: "email", password: "password")

switch response {
case let .session(session):
    // User created, and doesn't require email confirmation, so a Session was already returned.

case let .user(user):
    // User created but requires email confirmation.
}

I hope this helps, if you still face any issues, let me know.

Thank you.

@marcusraty
Copy link
Author

marcusraty commented Dec 5, 2023

Thanks for your reply!

The following code shows a valid session but a nil user:

let result = try await supabaseClient.auth.signUp(
                email: email,
                password: password,
                data: metadata
            )
print("result is", result)
print("user is", result.user)

I would expect both the result and user to have valid values, because I have turned off email confirmation in my supabase.

Running your switch code and printing out the session/user - only shows a user.

I was running this code before using client.signUp(email: "email", password: "password") but have just today started using the data parameter, and a Trigger to populate a public.profiles table from the metadata.

Note: my code also have an auth listener onAuthStateChange() and immediately following this method, even through user is nil, it fires that the user who just signed up is now logged in.

@grdsdev
Copy link
Collaborator

grdsdev commented Dec 5, 2023

Thank you @marcusraty, here is a fix for it #174, I'll make a new release once it gets merged.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants