letourpowerscombine
11/10/2021, 1:52 PMusers
table with a new UUID — but the returned value is null.
let { user, error } = await supabase.auth.signIn({
email: formData.get('email')
})
Is there anyway to return the newly created user's UUID / user object from this function?
(I have turned off "Enable email confirmations" in the auth settings, to make it easier)silentworks
11/10/2021, 1:52 PMusers
table with a new UUID — but the returned value is null.
let { user, error } = await supabase.auth.signIn({
email: formData.get('email')
})
Is there anyway to return the newly created user's UUID / user object from this function?
(I have turned off "Enable email confirmations" in the auth settings, to make it easier)silentworks
11/10/2021, 1:53 PMdata
not user
, try that and see if you get the correct information backletourpowerscombine
11/10/2021, 1:56 PMdata
for user
, here's the full function — still returning null:
javascript
async function addEmail(e) {
let formData = new FormData(e.target);
console.log(formData.get('email'));
let { data, error } = await supabase.auth.signIn({
email: formData.get('email')
})
if (data) {
console.log(data);
let new_user = data;
profile_form = true;
return data;
}
else {
console.log(error);
}
}
@Usersilentworks
11/10/2021, 1:58 PMsilentworks
11/10/2021, 1:58 PMsilentworks
11/10/2021, 1:59 PMletourpowerscombine
11/10/2021, 2:01 PMsilentworks
11/10/2021, 2:02 PMsilentworks
11/10/2021, 2:02 PMletourpowerscombine
11/10/2021, 2:08 PMletourpowerscombine
11/10/2021, 2:10 PMletourpowerscombine
11/10/2021, 2:11 PMsilentworks
11/10/2021, 2:11 PMletourpowerscombine
11/10/2021, 2:13 PMprofiles
table on capture, so I don't need to worry about a different form collection tool, and all of the profile information will be ready once the application is live and dealing with authenticationletourpowerscombine
11/10/2021, 2:14 PMsilentworks
11/10/2021, 2:14 PMsilentworks
11/10/2021, 2:14 PMsilentworks
11/10/2021, 2:15 PMsignIn
functionsilentworks
11/10/2021, 2:17 PMjs
const { data, error } = await supabase.auth.signIn(
{ email },
{
data: {
full_name,
website,
twitter
}
})
silentworks
11/10/2021, 2:17 PMprofiles
tablesilentworks
11/10/2021, 2:18 PMsilentworks
11/10/2021, 2:18 PMsilentworks
11/10/2021, 2:20 PMadditional data
section inside of a trigger function, you would do something like the below
sql
create function public.handle_new_profile()
returns trigger as $$
begin
insert into public.profiles (user_id, full_name, website)
values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'website');
return new;
end;
$$ language plpgsql security definer;
silentworks
11/10/2021, 2:20 PMletourpowerscombine
11/10/2021, 2:20 PMletourpowerscombine
11/10/2021, 2:21 PMsilentworks
11/10/2021, 2:21 PMsignIn
function until step 2 is completedletourpowerscombine
11/10/2021, 2:21 PMsilentworks
11/10/2021, 2:22 PMletourpowerscombine
11/10/2021, 2:41 PM{data}
is getting entered. Here's my function call:
javascript
const { data, error } = await supabase.auth.signIn(
{ email: localStorage.getItem('email') },
{
data: {
full_name: formData.get('full_name'),
introduction: formData.get('introduction'),
website_url: formData.get('website_url'),
linkedin_url: formData.get('linkedin_url'),
twitter_handle: formData.get('twitter_handle'),
contact_method: formData.get('contact_method')
}
})
And here is the function/trigger:
sql
create function public.handle_new_profile()
returns trigger as $$
begin
insert into public.profiles (user_id, user_email, full_name, introduction, website_url, linkedin_url, twitter_handle, contact_method )
values (new.id, new.email, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'introduction', new.raw_user_meta_data->>'website_url', new.raw_user_meta_data->>'linkedin_url', new.raw_user_meta_data->>'twitter_handle', new.raw_user_meta_data->>'contact_method');
return new;
end;
$$ language plpgsql security definer;
-- trigger the function every time a user is created
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_profile();
I imagine it's just some syntax thing, that I'm not calling the submitted form data correctly in the Insert function. Any thoughts on that?silentworks
11/10/2021, 2:45 PMformData.get('ful_name')
and so onsilentworks
11/10/2021, 2:46 PMprofiles
table are being setletourpowerscombine
11/10/2021, 2:55 PMjavascript
const { data, error } = await supabase.auth.signIn(
{ email: localStorage.getItem('email') },
{
data: {
full_name: "test",
introduction: "test",
website_url: "test",
linkedin_url: "test",
twitter_handle: "test",
contact_method: "test"
}
})
Same result — none of the information in { data: {} }
is appearing in the profiles table when the new profiles are createdsilentworks
11/10/2021, 3:04 PMletourpowerscombine
11/10/2021, 3:05 PMletourpowerscombine
11/10/2021, 4:18 PMletourpowerscombine
11/10/2021, 5:37 PMjavascript
async signIn(
{ email, phone, password, refreshToken, provider }: UserCredentials,
options: {
redirectTo?: string
scopes?: string
} = {}
compared to signUp which does seem to have data property:
javascript
async signUp(
{ email, password, phone }: UserCredentials,
options: {
redirectTo?: string
data?: object
} = {}
With that in mind, any other ideas as to how I can do what I'm trying to do? Create a user just with email
, and then add form data to the user's profile
, without authentication in the middle?YelloJello
11/10/2021, 5:44 PMsilentworks
11/10/2021, 5:46 PMYelloJello
11/10/2021, 5:48 PMletourpowerscombine
11/10/2021, 5:49 PMsignUp
function.
2. Generating a random password for users in the background and running signUp
with the randomly generated passwords, and then when there is a real application and sign-in flow, just forcing users to sign in with magic link or reset their passwords?letourpowerscombine
11/10/2021, 5:50 PMYelloJello
11/10/2021, 5:50 PMsilentworks
11/10/2021, 5:51 PMsilentworks
11/10/2021, 5:51 PMsilentworks
11/10/2021, 5:53 PMsilentworks
11/10/2021, 5:53 PMletourpowerscombine
11/10/2021, 5:53 PMjavascript
let { user, error } = await supabase.auth.signUp({
email: 'new_user@email.com',
password: '{RANDOMLY_GENERATED_PASSWORD}'
}, { data: {
full_name: "name",
introduction: "hello I'm name",
website_url: "example.com",
linkedin_url: "linkedin.com",
twitter_handle: "@name",
contact_method: "reach me here "
}
}
})
letourpowerscombine
11/10/2021, 5:54 PMletourpowerscombine
11/10/2021, 5:56 PMsilentworks
11/10/2021, 5:58 PMYelloJello
11/10/2021, 6:00 PMsilentworks
11/10/2021, 6:00 PMsilentworks
11/10/2021, 6:01 PMletourpowerscombine
11/10/2021, 6:02 PMletourpowerscombine
11/10/2021, 6:02 PMsilentworks
11/10/2021, 6:04 PMinvite
table without a user_id
, then use the inviteUserByEmail
functionality later to deal with the signUp process https://supabase.io/docs/reference/javascript/auth-api-inviteuserbyemailsilentworks
11/10/2021, 6:05 PMinviteUserByEmail
requires the service_role
keyletourpowerscombine
11/10/2021, 6:10 PMsilentworks
11/10/2021, 6:11 PMinviteUserByEmail
functionsilentworks
11/10/2021, 6:12 PMjs
const { user, error } = await supabase.auth.api
.inviteUserByEmail('email@example.com', { data: {
full_name: "name",
introduction: "hello I'm name",
website_url: "example.com",
linkedin_url: "linkedin.com",
twitter_handle: "@name",
contact_method: "reach me here "
}})
letourpowerscombine
11/10/2021, 6:13 PMsilentworks
11/10/2021, 6:13 PMsilentworks
11/10/2021, 6:14 PMletourpowerscombine
11/10/2021, 6:14 PMletourpowerscombine
11/10/2021, 6:15 PMsilentworks
11/10/2021, 6:15 PMsilentworks
11/10/2021, 6:15 PMsilentworks
11/10/2021, 6:16 PMletourpowerscombine
11/10/2021, 6:18 PMletourpowerscombine
11/10/2021, 10:07 PMsilentworks
11/10/2021, 10:08 PM