File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,11 @@ fn authenticate_user(req: &dyn RequestExt) -> AppResult<AuthenticatedUser> {
62
62
let session = req. session ( ) ;
63
63
let user_id_from_session = session. get ( "user_id" ) . and_then ( |s| s. parse :: < i32 > ( ) . ok ( ) ) ;
64
64
65
- let ( user_id, token_id) = if let Some ( id) = user_id_from_session {
66
- ( id, None )
65
+ let ( user, token_id) = if let Some ( id) = user_id_from_session {
66
+ let user = User :: find ( & conn, id)
67
+ . chain_error ( || internal ( "user_id from cookie not found in database" ) ) ?;
68
+
69
+ ( user, None )
67
70
} else {
68
71
// Otherwise, look for an `Authorization` header on the request
69
72
let maybe_authorization = req
@@ -80,16 +83,16 @@ fn authenticate_user(req: &dyn RequestExt) -> AppResult<AuthenticatedUser> {
80
83
}
81
84
} ) ?;
82
85
83
- ( token. user_id , Some ( token. id ) )
86
+ let user = User :: find ( & conn, token. user_id )
87
+ . chain_error ( || internal ( "user_id from token not found in database" ) ) ?;
88
+
89
+ ( user, Some ( token. id ) )
84
90
} else {
85
91
// Unable to authenticate the user
86
92
return Err ( internal ( "no cookie session or auth header found" ) ) . chain_error ( forbidden) ;
87
93
}
88
94
} ;
89
95
90
- let user = User :: find ( & conn, user_id)
91
- . chain_error ( || internal ( "user_id from cookie or token not found in database" ) ) ?;
92
-
93
96
Ok ( AuthenticatedUser { user, token_id } )
94
97
}
95
98
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ static URL: &str = "/api/v1/me/updates";
8
8
static MUST_LOGIN : & [ u8 ] =
9
9
b"{\" errors\" :[{\" detail\" :\" must be logged in to perform that action\" }]}" ;
10
10
static INTERNAL_ERROR_NO_USER : & str =
11
- "user_id from cookie or token not found in database caused by NotFound" ;
11
+ "user_id from cookie not found in database caused by NotFound" ;
12
12
13
13
fn call ( app : & TestApp , mut request : MockRequest ) -> HandlerResult {
14
14
app. as_middleware ( ) . call ( & mut request)
You can’t perform that action at this time.
0 commit comments