mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
chore(api): move token auth to rust api service
This commit is contained in:
parent
8210cb23f6
commit
cfde105e19
8 changed files with 83 additions and 27 deletions
20
lib/libpk/src/db/repository/auth.rs
Normal file
20
lib/libpk/src/db/repository/auth.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
pub async fn legacy_token_auth(
|
||||
pool: &sqlx::postgres::PgPool,
|
||||
token: &str,
|
||||
) -> anyhow::Result<Option<i32>> {
|
||||
let mut system: Vec<LegacyTokenDbResponse> =
|
||||
sqlx::query_as("select id from systems where token = $1")
|
||||
.bind(token)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(if let Some(system) = system.pop() {
|
||||
Some(system.id)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct LegacyTokenDbResponse {
|
||||
id: i32,
|
||||
}
|
||||
|
|
@ -1,2 +1,5 @@
|
|||
mod stats;
|
||||
pub use stats::*;
|
||||
|
||||
mod auth;
|
||||
pub use auth::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue