Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSBookMinigames
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
SSBookMinigames
Commits
9fa6f827
Commit
9fa6f827
authored
Apr 14, 2026
by
Yousef Sameh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better auth error messages & leaderboard always include current player
parent
cbf5e7b9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
160 deletions
+160
-160
SupabaseAuthentication.cs
.../Assets/App/Infrastructure/Auth/SupabaseAuthentication.cs
+112
-99
LeaderboardService.cs
...sets/App/Infrastructure/Leaderboard/LeaderboardService.cs
+7
-5
LeaderboardController.cs
My project/Assets/App/UI/LeaderboardController.cs
+12
-13
LoginPageAnimation.cs
My project/Assets/AppUI/Scripts/LoginPageAnimation.cs
+29
-43
No files found.
My project/Assets/App/Infrastructure/Auth/SupabaseAuthentication.cs
View file @
9fa6f827
This diff is collapsed.
Click to expand it.
My project/Assets/App/Infrastructure/Leaderboard/LeaderboardService.cs
View file @
9fa6f827
...
...
@@ -11,16 +11,18 @@ public class LeaderboardService
private
Client
supabase
=>
SupabaseManager
.
Instance
.
Supabase
();
public
async
UniTask
<
OneOf
<
List
<
LeaderboardPlayerModel
>,
string
>>
LoadTop100Players
()
public
async
UniTask
<
OneOf
<
List
<
LeaderboardPlayerModel
>,
string
>>
LoadTop100Players
AndCurrentPlayer
()
{
var
currentUserId
=
UserService
.
Instance
.
CurrentUser
?.
Id
;
if
(
string
.
IsNullOrEmpty
(
currentUserId
))
return
new
List
<
LeaderboardPlayerModel
>();
try
{
// Queries the 'leaderboard' view directly
var
response
=
await
supabase
.
From
<
LeaderboardPlayerModel
>()
.
Get
();
.
Rpc
<
List
<
LeaderboardPlayerModel
>>(
"get_leaderboard_with_user"
,
new
{
target_user_id
=
currentUserId
});
return
response
.
Models
;
return
response
;
}
catch
(
Exception
e
)
{
...
...
My project/Assets/App/UI/LeaderboardController.cs
View file @
9fa6f827
using
System
;
using
System.Collections.Generic
;
using
System.Threading
;
// Required for CancellationTokenSource
using
System.Threading
;
using
Cysharp.Threading.Tasks
;
using
UnityEngine
;
using
UnityEngine.UIElements
;
...
...
@@ -12,17 +12,16 @@ public class LeaderboardController : MonoBehaviour, IDisposable
private
VisualElement
allPlayersContainer
;
private
VisualElement
root
;
// Stores the active cancellation token
private
CancellationTokenSource
_loadCts
;
public
int
CurrentPlayerSlotIndex
{
get
;
private
set
;
}
=
-
1
;
void
Start
()
{
root
=
leaderboardDocument
.
rootVisualElement
;
allPlayersContainer
=
root
.
Q
<
VisualElement
>(
"AllPlayerContainer"
);
// Fixed Event Subscription: Use a named method to avoid memory leaks!
UserService
.
Instance
.
OnUserChanged
+=
OnUserChanged
;
LoadLeaderboard
().
Forget
();
}
...
...
@@ -52,31 +51,34 @@ public class LeaderboardController : MonoBehaviour, IDisposable
try
{
// Note: If you can edit LeaderboardService, update LoadTop100Players()
// to accept this CancellationToken to cancel the actual web request!
// Example: await LeaderboardService.Instance.LoadTop100Players(token);
var
result
=
await
LeaderboardService
.
Instance
.
LoadTop100Players
();
var
result
=
await
LeaderboardService
.
Instance
.
LoadTop100PlayersAndCurrentPlayer
();
// 3. Check if a newer request cancelled this one while we were waiting
if
(
token
.
IsCancellationRequested
)
return
;
result
.
Switch
(
(
List
<
LeaderboardPlayerModel
>
players
)
=>
{
CurrentPlayerSlotIndex
=
-
1
;
for
(
int
i
=
0
;
i
<
players
.
Count
;
i
++)
{
if
(
i
<
3
)
ApplyTopThree
(
i
,
players
[
i
]);
var
player
=
players
[
i
];
var
isOwner
=
player
.
Id
==
UserService
.
Instance
.
CurrentUser
?.
Id
;
if
(
isOwner
)
CurrentPlayerSlotIndex
=
i
;
var
entry
=
new
CustomLeaderboardSlot
{
PlayerName
=
player
.
UserName
,
Rank
=
player
.
Rank
,
XP
=
player
.
Points
.
ToString
(),
Index
=
player
.
Position
.
ToString
(),
IsOwner
=
player
.
Id
==
UserService
.
Instance
.
CurrentUser
?.
Id
IsOwner
=
isOwner
};
allPlayersContainer
.
Add
(
entry
);
...
...
@@ -124,13 +126,11 @@ public class LeaderboardController : MonoBehaviour, IDisposable
public
void
Dispose
()
{
// Now safely removes the event listener
if
(
UserService
.
Instance
!=
null
)
{
UserService
.
Instance
.
OnUserChanged
-=
OnUserChanged
;
}
// Cancel any pending load when this object is destroyed/disposed
if
(
_loadCts
!=
null
)
{
_loadCts
.
Cancel
();
...
...
@@ -139,7 +139,6 @@ public class LeaderboardController : MonoBehaviour, IDisposable
}
}
// Good practice in Unity to ensure Dispose runs if the GameObject is destroyed
private
void
OnDestroy
()
{
Dispose
();
...
...
My project/Assets/AppUI/Scripts/LoginPageAnimation.cs
View file @
9fa6f827
...
...
@@ -3,13 +3,7 @@ using System;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.UIElements
;
[Serializable]
public
class
SupabaseError
{
public
int
code
;
public
string
error_code
;
public
string
msg
;
}
public
class
LoginPageAnimation
:
MonoBehaviour
{
[
SerializeField
]
UIDocument
loginPage
;
...
...
@@ -24,6 +18,8 @@ public class LoginPageAnimation : MonoBehaviour
PlayerPrefs
.
SetInt
(
"IsGuest"
,
0
);
SupabaseAuthentication
.
Instance
.
UseArabicErrors
=
true
;
if
(
Application
.
internetReachability
==
NetworkReachability
.
NotReachable
)
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"يرجي الأتصال بالإنترنت وأعد المحاولة"
,
true
);
...
...
@@ -162,7 +158,7 @@ public class LoginPageAnimation : MonoBehaviour
},
error
=>
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"فشل تسجيل الدخول، يرجى التحقق من البريد الإلكتروني وكلمة المرور"
);
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
loginButton
.
SetEnabled
(
true
);
loginButton
.
text
=
"تسجيل الدخول"
;
}
...
...
@@ -281,10 +277,8 @@ public class LoginPageAnimation : MonoBehaviour
},
error
=>
{
// debug error code and message
Debug
.
LogError
(
$"ConvertGuestToEmail error:
{
error
}
"
);
ShowUIMessage
.
Instance
.
ShowMessage
(
"فشل إنشاء الحساب، يرجى المحاولة مرة أخرى"
);
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
registerButton
.
SetEnabled
(
true
);
registerButton
.
text
=
"تسجيل"
;
}
...
...
@@ -313,19 +307,7 @@ public class LoginPageAnimation : MonoBehaviour
},
error
=>
{
var
json
=
error
.
ToString
();
var
parsed
=
JsonUtility
.
FromJson
<
SupabaseError
>(
json
);
if
(
parsed
.
code
==
422
)
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"الحساب مسجل بالفعل، يرجى تسجيل الدخول"
);
}
else
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"فشل إنشاء الحساب، يرجى المحاولة مرة أخرى"
);
}
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
registerButton
.
SetEnabled
(
true
);
registerButton
.
text
=
"تسجيل"
;
}
...
...
@@ -397,7 +379,7 @@ public class LoginPageAnimation : MonoBehaviour
error
=>
{
Debug
.
LogError
(
"Registration error: "
+
error
);
ShowUIMessage
.
Instance
.
ShowMessage
(
"فشل إنشاء الحساب، يرجى المحاولة مرة أخرى"
);
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
registerButton
.
SetEnabled
(
true
);
registerButton
.
text
=
"تسجيل"
;
}
...
...
@@ -466,15 +448,17 @@ public class LoginPageAnimation : MonoBehaviour
sendEmail
.
SetEnabled
(
false
);
closeForgetPasswordPanel
.
SetEnabled
(
false
);
try
{
await
SupabaseAuthentication
.
Instance
.
ResetPasswordRequest
(
forgetPasswordEmailField
.
text
);
ShowUIMessage
.
Instance
.
ShowMessage
(
"تم إرسال بريد إعادة تعيين كلمة المرور، يرجى التحقق من بريدك الإلكتروني"
);
}
catch
(
Exception
ex
)
{
Debug
.
LogException
(
ex
);
}
var
result
=
await
SupabaseAuthentication
.
Instance
.
ResetPasswordRequest
(
forgetPasswordEmailField
.
text
);
result
.
Switch
(
success
=>
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"تم إرسال بريد إعادة تعيين كلمة المرور، يرجى التحقق من بريدك الإلكتروني"
);
},
error
=>
{
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
}
);
sendEmail
.
SetEnabled
(
true
);
closeForgetPasswordPanel
.
SetEnabled
(
true
);
...
...
@@ -523,15 +507,17 @@ public class LoginPageAnimation : MonoBehaviour
updatePassword
.
SetEnabled
(
false
);
try
{
await
SupabaseAuthentication
.
Instance
.
UpdatePassword
(
newPasswordField
.
text
);
ShowUIMessage
.
Instance
.
ShowMessage
(
"تم تحديث كلمة المرور بنجاح، يرجى تسجيل الدخول مرة أخرى"
);
}
catch
(
Exception
ex
)
{
Debug
.
LogException
(
ex
);
}
var
result
=
await
SupabaseAuthentication
.
Instance
.
UpdatePassword
(
newPasswordField
.
text
);
result
.
Switch
(
success
=>
{
ShowUIMessage
.
Instance
.
ShowMessage
(
"تم تحديث كلمة المرور بنجاح، يرجى تسجيل الدخول مرة أخرى"
);
},
error
=>
{
ShowUIMessage
.
Instance
.
ShowMessage
(
error
);
}
);
updatePassword
.
SetEnabled
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment