File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,11 @@ async fn validate_token(req: &HttpRequest) -> actix_web::Result<User> {
4747
4848 let ( token_id, exp) = extract_token ( token, & state. jwt_secret ) ?;
4949
50+ // Check expiration BEFORE doing any database operations
51+ if exp < Utc :: now ( ) . timestamp ( ) as usize {
52+ return Err ( ErrorUnauthorized ( "Session expired" ) ) ;
53+ }
54+
5055 let mut conn = get_connection ( state) ?;
5156 let refresh_token: RefreshToken = web_block_unpacked ( move || {
5257 use db_connector:: schema:: refresh_tokens:: dsl:: * ;
@@ -59,10 +64,8 @@ async fn validate_token(req: &HttpRequest) -> actix_web::Result<User> {
5964 } )
6065 . await ?;
6166
67+ // Only delete the token after we've confirmed it exists and is valid
6268 delete_refresh_token ( token_id, state) . await ?;
63- if exp < Utc :: now ( ) . timestamp ( ) as usize {
64- return Err ( ErrorUnauthorized ( "Session expired" ) ) ;
65- }
6669
6770 let mut conn = get_connection ( state) ?;
6871 let user: User = web_block_unpacked ( move || {
You can’t perform that action at this time.
0 commit comments