Commit 1723ae04 authored by Yousef Sameh's avatar Yousef Sameh

Auto create row on user sign up

parent 08e3cfbf
using System; using System;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using OneOf; using OneOf;
using Supabase.Gotrue;
using Supabase.Gotrue.Exceptions; using Supabase.Gotrue.Exceptions;
using UnityEngine; using UnityEngine;
...@@ -41,15 +42,19 @@ public class SupabaseAuthentication : MonoBehaviour ...@@ -41,15 +42,19 @@ public class SupabaseAuthentication : MonoBehaviour
} }
public async UniTask<OneOf<Success, string>> SignUp(string username, string password, string displayName) public async UniTask<OneOf<Success, string>> SignUp(string email, string password, string displayName)
{ {
try try
{ {
IsLoading = true; IsLoading = true;
await supabaseManager.Supabase()!.Auth.SignUp(username, password); await supabaseManager.Supabase()!.Auth.SignUp(email, password);
await UserService.Instance.CreateUserProfile(displayName); var userProfile = await UserService.Instance.CreateUserProfile(displayName);
return new Success(); userProfile.Switch((_) => { }, (error) =>
{
Debug.LogError(error);
});
return new Success();
} }
catch (GotrueException gotrueexception) catch (GotrueException gotrueexception)
{ {
......
...@@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks; ...@@ -2,6 +2,7 @@ using Cysharp.Threading.Tasks;
using OneOf; using OneOf;
using Supabase; using Supabase;
using System; using System;
using UnityEngine;
public class UserService : Singleton<UserService> public class UserService : Singleton<UserService>
{ {
...@@ -19,16 +20,11 @@ public class UserService : Singleton<UserService> ...@@ -19,16 +20,11 @@ public class UserService : Singleton<UserService>
{ {
try try
{ {
var authUser = supabase.Auth.CurrentUser;
if (authUser == null)
return new ErrorResult("Not authenticated");
var user = new User var user = new User
{ {
Id = authUser.Id.ToString(),
DisplayName = displayName, DisplayName = displayName,
AvatarUrl = avatarUrl, AvatarUrl = avatarUrl,
Rank = UserRank.Normal, Rank = "normal",
Points = 0, Points = 0,
CreatedAt = DateTime.UtcNow, CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow UpdatedAt = DateTime.UtcNow
......
...@@ -2,6 +2,9 @@ using System; ...@@ -2,6 +2,9 @@ using System;
using Supabase.Postgrest.Attributes; using Supabase.Postgrest.Attributes;
using Supabase.Postgrest.Models; using Supabase.Postgrest.Models;
using System.Text.Json.Serialization;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum UserRank public enum UserRank
{ {
Normal, Normal,
...@@ -23,7 +26,7 @@ public class User : BaseModel ...@@ -23,7 +26,7 @@ public class User : BaseModel
public string? AvatarUrl { get; set; } public string? AvatarUrl { get; set; }
[Column("rank")] [Column("rank")]
public UserRank Rank { get; set; } = UserRank.Normal; public string Rank { get; set; }
[Column("points")] [Column("points")]
public int Points { get; set; } = 0; public int Points { get; set; } = 0;
......
...@@ -14,6 +14,6 @@ public class SupabaseTester : MonoBehaviour ...@@ -14,6 +14,6 @@ public class SupabaseTester : MonoBehaviour
[ContextMenu("Sign Up")] [ContextMenu("Sign Up")]
public void SignUp() public void SignUp()
{ {
supabaseAuthentication.SignUp("test@gmail.com", "test098", "p0wer"); supabaseAuthentication.SignUp("hello@gmail.com", "test098", "p0wer");
} }
} }
...@@ -41,7 +41,9 @@ public class CreateAcountUI : MonoBehaviour ...@@ -41,7 +41,9 @@ public class CreateAcountUI : MonoBehaviour
string displayName = displayNameInputField.text; string displayName = displayNameInputField.text;
string email = emailInputField.text; string email = emailInputField.text;
string password = passwordInputField.text; string password = passwordInputField.text;
var SignUp = await SupabaseAuthentication.Instance.SignUp(email, password); print(email);
print(password);
var SignUp = await SupabaseAuthentication.Instance.SignUp(email, password, displayName);
SignUp.Switch( SignUp.Switch(
(_) => { }, (_) => { },
(string error) => { messageText.text = error; } (string error) => { messageText.text = error; }
......
...@@ -48,6 +48,7 @@ public class LoginUI : MonoBehaviour ...@@ -48,6 +48,7 @@ public class LoginUI : MonoBehaviour
{ {
string email = emailInputField.text; string email = emailInputField.text;
string password = passwordInputField.text; string password = passwordInputField.text;
print(email);
var login = await SupabaseAuthentication.Instance.LogIn(email, password); var login = await SupabaseAuthentication.Instance.LogIn(email, password);
login.Switch( login.Switch(
(_) => { }, (_) => { },
......
...@@ -728,8 +728,8 @@ MonoBehaviour: ...@@ -728,8 +728,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::CreateAcountUI m_EditorClassIdentifier: Assembly-CSharp::CreateAcountUI
displayNameInputField: {fileID: 675010771} displayNameInputField: {fileID: 675010771}
emailInputField: {fileID: 1253017572} emailInputField: {fileID: 1033481300}
passwordInputField: {fileID: 1591207985} passwordInputField: {fileID: 638522057}
createAcountButton: {fileID: 14167333} createAcountButton: {fileID: 14167333}
loginPanelButton: {fileID: 757821088} loginPanelButton: {fileID: 757821088}
messageText: {fileID: 1874488904} messageText: {fileID: 1874488904}
......
...@@ -33,10 +33,10 @@ EditorUserSettings: ...@@ -33,10 +33,10 @@ EditorUserSettings:
value: 5701055506000a030f5c542744260844404f4d73797975367c2c1e6ab7e2653d value: 5701055506000a030f5c542744260844404f4d73797975367c2c1e6ab7e2653d
flags: 0 flags: 0
RecentlyUsedSceneGuid-8: RecentlyUsedSceneGuid-8:
value: 5200570406560d58095e5c75432609124f154e737a2d2432787e4b62b4e1366a value: 0152005506515f5d0e5f5a7b46770d1317154c7d7d7f7734747a196ae0b26668
flags: 0 flags: 0
RecentlyUsedSceneGuid-9: RecentlyUsedSceneGuid-9:
value: 0152005506515f5d0e5f5a7b46770d1317154c7d7d7f7734747a196ae0b26668 value: 5200570406560d58095e5c75432609124f154e737a2d2432787e4b62b4e1366a
flags: 0 flags: 0
UnityEditor.ShaderGraph.Blackboard: UnityEditor.ShaderGraph.Blackboard:
value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba75e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1bf968e93e2ffcbc3e7e2f0b3ffe0e8b0be9af8ffaeffff8e85dd8390e3949c8899daa7 value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba75e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1bf968e93e2ffcbc3e7e2f0b3ffe0e8b0be9af8ffaeffff8e85dd8390e3949c8899daa7
......
...@@ -24,7 +24,7 @@ MonoBehaviour: ...@@ -24,7 +24,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 112} m_MinSize: {x: 300, y: 112}
m_MaxSize: {x: 24288, y: 16192} m_MaxSize: {x: 24288, y: 16192}
vertical: 0 vertical: 0
controlID: 1397 controlID: 4036
draggingID: 0 draggingID: 0
--- !u!114 &2 --- !u!114 &2
MonoBehaviour: MonoBehaviour:
...@@ -50,7 +50,7 @@ MonoBehaviour: ...@@ -50,7 +50,7 @@ MonoBehaviour:
x: 355 x: 355
y: 61 y: 61
width: 1097 width: 1097
height: 652 height: 433
m_SerializedDataModeController: m_SerializedDataModeController:
m_DataMode: 0 m_DataMode: 0
m_PreferredDataMode: 0 m_PreferredDataMode: 0
...@@ -107,22 +107,22 @@ MonoBehaviour: ...@@ -107,22 +107,22 @@ MonoBehaviour:
x: 0 x: 0
y: 21 y: 21
width: 1097 width: 1097
height: 631 height: 412
m_Scale: {x: 0.26291665, y: 0.26291665} m_Scale: {x: 0.17166667, y: 0.17166667}
m_Translation: {x: 548.5, y: 315.5} m_Translation: {x: 548.5, y: 206}
m_MarginLeft: 0 m_MarginLeft: 0
m_MarginRight: 0 m_MarginRight: 0
m_MarginTop: 0 m_MarginTop: 0
m_MarginBottom: 0 m_MarginBottom: 0
m_LastShownAreaInsideMargins: m_LastShownAreaInsideMargins:
serializedVersion: 2 serializedVersion: 2
x: -2086.2124 x: -3195.1455
y: -1200 y: -1200
width: 4172.425 width: 6390.291
height: 2400 height: 2400
m_MinimalGUI: 1 m_MinimalGUI: 1
m_defaultScale: 0.26291665 m_defaultScale: 0.17166667
m_LastWindowPixelSize: {x: 1097, y: 652} m_LastWindowPixelSize: {x: 1097, y: 433}
m_ClearInEditMode: 1 m_ClearInEditMode: 1
m_NoCameraWarning: 1 m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000000000000 m_LowResolutionForAspectRatios: 01000000000000000000
...@@ -153,7 +153,7 @@ MonoBehaviour: ...@@ -153,7 +153,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 112} m_MinSize: {x: 200, y: 112}
m_MaxSize: {x: 16192, y: 16192} m_MaxSize: {x: 16192, y: 16192}
vertical: 1 vertical: 1
controlID: 1398 controlID: 4037
draggingID: 0 draggingID: 0
--- !u!114 &4 --- !u!114 &4
MonoBehaviour: MonoBehaviour:
...@@ -175,11 +175,11 @@ MonoBehaviour: ...@@ -175,11 +175,11 @@ MonoBehaviour:
x: 0 x: 0
y: 0 y: 0
width: 1454 width: 1454
height: 678 height: 459
m_MinSize: {x: 200, y: 56} m_MinSize: {x: 200, y: 56}
m_MaxSize: {x: 16192, y: 8096} m_MaxSize: {x: 16192, y: 8096}
vertical: 0 vertical: 0
controlID: 1399 controlID: 4038
draggingID: 0 draggingID: 0
--- !u!114 &5 --- !u!114 &5
MonoBehaviour: MonoBehaviour:
...@@ -199,7 +199,7 @@ MonoBehaviour: ...@@ -199,7 +199,7 @@ MonoBehaviour:
x: 0 x: 0
y: 0 y: 0
width: 355 width: 355
height: 678 height: 459
m_MinSize: {x: 201, y: 226} m_MinSize: {x: 201, y: 226}
m_MaxSize: {x: 4001, y: 4026} m_MaxSize: {x: 4001, y: 4026}
m_ActualView: {fileID: 6} m_ActualView: {fileID: 6}
...@@ -231,7 +231,7 @@ MonoBehaviour: ...@@ -231,7 +231,7 @@ MonoBehaviour:
x: 0 x: 0
y: 61 y: 61
width: 354 width: 354
height: 652 height: 433
m_SerializedDataModeController: m_SerializedDataModeController:
m_DataMode: 0 m_DataMode: 0
m_PreferredDataMode: 0 m_PreferredDataMode: 0
...@@ -247,13 +247,18 @@ MonoBehaviour: ...@@ -247,13 +247,18 @@ MonoBehaviour:
m_DynamicPanelBehavior: 0 m_DynamicPanelBehavior: 0
m_SceneHierarchy: m_SceneHierarchy:
m_TreeViewState: m_TreeViewState:
scrollPos: {x: 0, y: 0} scrollPos: {x: 0, y: 36}
m_SelectedIDs: m_SelectedIDs:
- m_Data: 31262 - m_Data: 31262
m_LastClickedID: m_LastClickedID:
m_Data: 0 m_Data: 0
m_ExpandedIDs: m_ExpandedIDs:
- m_Data: -8818
- m_Data: -1342 - m_Data: -1342
- m_Data: 55606
- m_Data: 55648
- m_Data: 55828
- m_Data: 55890
m_RenameOverlay: m_RenameOverlay:
m_UserAcceptedRename: 0 m_UserAcceptedRename: 0
m_Name: m_Name:
...@@ -297,9 +302,9 @@ MonoBehaviour: ...@@ -297,9 +302,9 @@ MonoBehaviour:
x: 355 x: 355
y: 0 y: 0
width: 1099 width: 1099
height: 678 height: 459
m_MinSize: {x: 200, y: 200} m_MinSize: {x: 202, y: 226}
m_MaxSize: {x: 4000, y: 4000} m_MaxSize: {x: 4002, y: 4026}
m_ActualView: {fileID: 2} m_ActualView: {fileID: 2}
m_Panes: m_Panes:
- {fileID: 8} - {fileID: 8}
...@@ -330,7 +335,7 @@ MonoBehaviour: ...@@ -330,7 +335,7 @@ MonoBehaviour:
x: 355 x: 355
y: 61 y: 61
width: 1097 width: 1097
height: 652 height: 433
m_SerializedDataModeController: m_SerializedDataModeController:
m_DataMode: 0 m_DataMode: 0
m_PreferredDataMode: 0 m_PreferredDataMode: 0
...@@ -1019,9 +1024,9 @@ MonoBehaviour: ...@@ -1019,9 +1024,9 @@ MonoBehaviour:
m_Position: m_Position:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
y: 678 y: 459
width: 1454 width: 1454
height: 305 height: 524
m_MinSize: {x: 231, y: 276} m_MinSize: {x: 231, y: 276}
m_MaxSize: {x: 10001, y: 10026} m_MaxSize: {x: 10001, y: 10026}
m_ActualView: {fileID: 10} m_ActualView: {fileID: 10}
...@@ -1054,9 +1059,9 @@ MonoBehaviour: ...@@ -1054,9 +1059,9 @@ MonoBehaviour:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
y: 739 y: 520
width: 1453 width: 1453
height: 279 height: 498
m_SerializedDataModeController: m_SerializedDataModeController:
m_DataMode: 0 m_DataMode: 0
m_PreferredDataMode: 0 m_PreferredDataMode: 0
...@@ -1081,7 +1086,7 @@ MonoBehaviour: ...@@ -1081,7 +1086,7 @@ MonoBehaviour:
m_SkipHidden: 0 m_SkipHidden: 0
m_SearchArea: 1 m_SearchArea: 1
m_Folders: m_Folders:
- Assets/App/Infrastructure/User - Assets/App/Infrastructure/Core
m_Globs: [] m_Globs: []
m_ProductIds: m_ProductIds:
m_AnyWithAssetOrigin: 0 m_AnyWithAssetOrigin: 0
...@@ -1091,7 +1096,7 @@ MonoBehaviour: ...@@ -1091,7 +1096,7 @@ MonoBehaviour:
m_ViewMode: 1 m_ViewMode: 1
m_StartGridSize: 96 m_StartGridSize: 96
m_LastFolders: m_LastFolders:
- Assets/App/Infrastructure/User - Assets/App/Infrastructure/Core
m_LastFoldersGridSize: 96 m_LastFoldersGridSize: 96
m_LastProjectPath: /home/p0wer/development/ssbookminigames/My project m_LastProjectPath: /home/p0wer/development/ssbookminigames/My project
m_LockTracker: m_LockTracker:
...@@ -1100,9 +1105,9 @@ MonoBehaviour: ...@@ -1100,9 +1105,9 @@ MonoBehaviour:
m_FolderTreeState: m_FolderTreeState:
scrollPos: {x: 0, y: 79} scrollPos: {x: 0, y: 79}
m_SelectedIDs: m_SelectedIDs:
- m_Data: 55232 - m_Data: 55224
m_LastClickedID: m_LastClickedID:
m_Data: 55232 m_Data: 55224
m_ExpandedIDs: m_ExpandedIDs:
- m_Data: 0 - m_Data: 0
- m_Data: 54850 - m_Data: 54850
...@@ -1230,9 +1235,9 @@ MonoBehaviour: ...@@ -1230,9 +1235,9 @@ MonoBehaviour:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
y: 739 y: 520
width: 1453 width: 1453
height: 279 height: 498
m_SerializedDataModeController: m_SerializedDataModeController:
m_DataMode: 0 m_DataMode: 0
m_PreferredDataMode: 0 m_PreferredDataMode: 0
...@@ -1361,8 +1366,8 @@ MonoBehaviour: ...@@ -1361,8 +1366,8 @@ MonoBehaviour:
y: 0 y: 0
width: 450 width: 450
height: 983 height: 983
m_MinSize: {x: 275, y: 50} m_MinSize: {x: 276, y: 76}
m_MaxSize: {x: 4000, y: 4000} m_MaxSize: {x: 4001, y: 4026}
m_ActualView: {fileID: 15} m_ActualView: {fileID: 15}
m_Panes: m_Panes:
- {fileID: 15} - {fileID: 15}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment