Skip to content

Commit 20b03f3

Browse files
committed
feat(auth): enhance verify-code endpoint to support anonymous account conversion
- Update auth middleware to include authenticated user retrieval - Modify completeEmailSignIn function to accept and process authenticated user - Enable conversion of anonymous accounts to permanent ones during sign-in - Improve code comments for clarity and maintainability
1 parent 04b8e94 commit 20b03f3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

routes/api/v1/auth/verify-code.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Future<Response> onRequest(RequestContext context) async {
1919
return Response(statusCode: HttpStatus.methodNotAllowed);
2020
}
2121

22-
// Read the AuthService provided by middleware.
23-
// The `authenticatedUser` is no longer needed here as the service handles
24-
// all context internally.
22+
// Read the AuthService and the currently authenticated user from middleware.
2523
final authService = context.read<AuthService>();
24+
final authenticatedUser = context.read<User?>();
2625

2726
// Parse the request body
2827
final dynamic body;
@@ -71,12 +70,14 @@ Future<Response> onRequest(RequestContext context) async {
7170
final isDashboardLogin = (body['isDashboardLogin'] as bool?) ?? false;
7271

7372
try {
74-
// Call the AuthService to handle the verification and sign-in logic
75-
// Pass the context flag to determine the correct flow.
73+
// Call the AuthService to handle the verification and sign-in logic.
74+
// Pass the authenticatedUser to allow for anonymous-to-permanent account
75+
// conversion.
7676
final result = await authService.completeEmailSignIn(
7777
email,
7878
code,
7979
isDashboardLogin: isDashboardLogin,
80+
authenticatedUser: authenticatedUser,
8081
);
8182

8283
// Create the specific payload containing user and token

0 commit comments

Comments
 (0)