@@ -15,16 +15,21 @@ class AuthHelper {
1515 password: password,
1616 );
1717
18- if (response.user != null ) {
19- final userId = response.user! .id;
20-
18+ final user = response.user;
19+ if (user != null ) {
20+ final userId = user.id;
21+ final userMetadata = user.userMetadata ?? {};
22+ final String ? username = userMetadata['username' ]? .toString ();
2123 final timezoneObj = await FlutterTimezone .getLocalTimezone ();
2224 final String currentTimezone = timezoneObj.toString ();
2325
2426 final profileData = await supabase
2527 .from ('profile' )
26- .update ({'timezone' : currentTimezone})
27- .eq ('id' , userId)
28+ .upsert ({
29+ 'id' : userId,
30+ if (username != null && username.isNotEmpty) 'username' : username,
31+ 'timezone' : currentTimezone,
32+ })
2833 .select ()
2934 .single ();
3035
@@ -77,14 +82,26 @@ class AuthHelper {
7782 }
7883 );
7984
80- if (response.user != null ) {
81- final userId = response.user! .id;
85+ final user = response.user;
86+ if (user != null ) {
87+ if (response.session == null ) {
88+ // Email confirmation may be required; skip profile write until login.
89+ return UserModel (
90+ id: user.id,
91+ email: email,
92+ username: username,
93+ timezone: currentTimezone,
94+ );
95+ }
8296
83- // Step 2: Insert directly into the 'profile' table
8497 final profileData = await supabase
8598 .from ('profile' )
99+ .upsert ({
100+ 'id' : user.id,
101+ 'username' : username,
102+ 'timezone' : currentTimezone,
103+ })
86104 .select ()
87- .eq ('id' , userId)
88105 .single ();
89106
90107 return UserModel .fromJson (profileData, email);
0 commit comments