Skip to content

Commit aad28a3

Browse files
committed
Let's reject invalid tokens now!
1 parent ed97ba8 commit aad28a3

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

src/api.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,9 @@ async fn identify_user(
118118
}
119119
};
120120

121-
// FIXME: return 403 if token is not present instead of warning
122121
if !token_present {
123122
warn!("Token not found for user: {} | {}", user_id, token);
124-
query!(
125-
r#"
126-
INSERT INTO api_tokens (user_id, token)
127-
VALUES ($1, $2)
128-
ON CONFLICT (user_id) DO UPDATE
129-
SET token=$2
130-
"#,
131-
&user_id,
132-
&token,
133-
)
134-
.execute(&state.db)
135-
.await
136-
.map_err(|err| {
137-
error!("Failed to save API token: {:?}", err);
138-
(
139-
StatusCode::INTERNAL_SERVER_ERROR,
140-
format!("Failed to save API token: {}", err)
141-
)
142-
})?;
123+
return Err((StatusCode::UNAUTHORIZED, "Invalid API token! Please generate a new one".to_string()));
143124
}
144125

145126
Ok((user_id, session_id))

0 commit comments

Comments
 (0)