Skip to content

Commit af9d55f

Browse files
committed
feat(auth): enhance email sign-in process
- Add current token extraction from Authorization header - Enhance anonymous-to-permanent account conversion - Support token invalidation in guest-to-permanent flow
1 parent 28b1185 commit af9d55f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,24 @@ Future<Response> onRequest(RequestContext context) async {
6969
// Check for the optional dashboard login flag. Default to false.
7070
final isDashboardLogin = (body['isDashboardLogin'] as bool?) ?? false;
7171

72+
// Extract the current token from the Authorization header, if it exists.
73+
// This is needed for the guest-to-permanent flow to invalidate the old token.
74+
final authHeader = context.request.headers[HttpHeaders.authorizationHeader];
75+
String? currentToken;
76+
if (authHeader != null && authHeader.startsWith('Bearer ')) {
77+
currentToken = authHeader.substring(7);
78+
}
79+
7280
try {
7381
// Call the AuthService to handle the verification and sign-in logic.
7482
// Pass the authenticatedUser to allow for anonymous-to-permanent account
75-
// conversion.
83+
// conversion, and the currentToken for invalidation.
7684
final result = await authService.completeEmailSignIn(
7785
email,
7886
code,
7987
isDashboardLogin: isDashboardLogin,
8088
authenticatedUser: authenticatedUser,
89+
currentToken: currentToken,
8190
);
8291

8392
// Create the specific payload containing user and token

0 commit comments

Comments
 (0)