ezidam: refactor jwt and refresh token generate in "tokens" mod
This commit is contained in:
parent
23b1e3ea4f
commit
9687116063
13 changed files with 179 additions and 59 deletions
6
crates/database/queries/keys/revoke_all_except_one.sql
Normal file
6
crates/database/queries/keys/revoke_all_except_one.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
update keys
|
||||
|
||||
set revoked_at = CURRENT_TIMESTAMP
|
||||
|
||||
where revoked_at is null
|
||||
and id is not (?)
|
||||
5
crates/database/queries/refresh_tokens/revoke_all.sql
Normal file
5
crates/database/queries/refresh_tokens/revoke_all.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
update refresh_tokens
|
||||
|
||||
set revoked_at = CURRENT_TIMESTAMP
|
||||
|
||||
where revoked_at is null
|
||||
|
|
@ -338,6 +338,16 @@
|
|||
},
|
||||
"query": "select id,\n created_at as \"created_at: DateTime<Utc>\",\n updated_at as \"updated_at: DateTime<Utc>\",\n is_admin as \"is_admin: bool\",\n username,\n name,\n email,\n password,\n password_recover,\n paper_key,\n is_archived as \"is_archived: bool\"\nfrom users\n\nwhere email is (?)\n"
|
||||
},
|
||||
"7b7f2430b2a719b3d5ce504c0a9302731b3ff82da99ba7771c2728d88aee642a": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "update keys\n\nset revoked_at = CURRENT_TIMESTAMP\n\nwhere revoked_at is null\n and id is not (?)\n"
|
||||
},
|
||||
"7f26b73408318040f94fb6574d5cc25482cef1a57ba4c467fa0bc0fdf25bf39c": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
|
@ -358,6 +368,16 @@
|
|||
},
|
||||
"query": "update settings\n\nset url = ?\n\nwhere id is 0\n"
|
||||
},
|
||||
"9f1885c4786f73335b4d614f562bb7cad49c91bfe7f084d8c25c6c571673ab90": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
}
|
||||
},
|
||||
"query": "update refresh_tokens\n\nset revoked_at = CURRENT_TIMESTAMP\n\nwhere revoked_at is null"
|
||||
},
|
||||
"a55b17a3a70e6445517f19536220f0dafc78a0e8b69221dee4715f84841839da": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
|
|
|||
|
|
@ -63,4 +63,17 @@ impl Keys {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn revoke_all_except_one(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
exception: &str,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let query: SqliteQueryResult =
|
||||
sqlx::query_file!("queries/keys/revoke_all_except_one.sql", exception)
|
||||
.execute(conn)
|
||||
.await
|
||||
.map_err(handle_error)?;
|
||||
|
||||
Ok((query.rows_affected() >= 1).then_some(()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,15 @@ impl RefreshTokens {
|
|||
Ok((query.rows_affected() == 1).then_some(()))
|
||||
}
|
||||
|
||||
pub async fn revoke_all(conn: impl SqliteExecutor<'_>) -> Result<Option<()>, Error> {
|
||||
let query: SqliteQueryResult = sqlx::query_file!("queries/refresh_tokens/revoke_all.sql")
|
||||
.execute(conn)
|
||||
.await
|
||||
.map_err(handle_error)?;
|
||||
|
||||
Ok((query.rows_affected() >= 1).then_some(()))
|
||||
}
|
||||
|
||||
pub async fn revoke_all_for_user(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
user: &str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue