mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-25 08:00:59 +00:00
refresh user tokens less aggressively
This commit is contained in:
@@ -1121,9 +1121,15 @@ paths:
|
||||
operationId: refreshUserToken
|
||||
tags:
|
||||
- user
|
||||
parameters:
|
||||
- name: if_expiring_in_less_than_s
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: int
|
||||
responses:
|
||||
"200":
|
||||
description: free usage
|
||||
description: new token
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
|
||||
@@ -2217,13 +2217,30 @@ async fn login(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RefreshTokenQuery {
|
||||
if_expiring_in_less_than_s: Option<i32>,
|
||||
}
|
||||
async fn refresh_token(
|
||||
Extension(db): Extension<DB>,
|
||||
Query(query): Query<RefreshTokenQuery>,
|
||||
Tokened { token }: Tokened,
|
||||
authed: ApiAuthed,
|
||||
cookies: Cookies,
|
||||
) -> Result<String> {
|
||||
let mut tx = db.begin().await?;
|
||||
|
||||
if let Some(thresh_s) = query.if_expiring_in_less_than_s {
|
||||
let not_expired = sqlx::query_scalar!("SELECT true FROM token WHERE token = $1 and expiration IS NOT NULL and expiration > now() + $2::int * '1 sec'::interval", &token, thresh_s)
|
||||
.fetch_optional(&db)
|
||||
.await?
|
||||
.flatten()
|
||||
.unwrap_or(false);
|
||||
if not_expired {
|
||||
return Ok("token expiry is far enough".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let super_admin = sqlx::query_scalar!(
|
||||
"SELECT super_admin FROM password WHERE email = $1",
|
||||
&authed.email
|
||||
|
||||
@@ -486,6 +486,7 @@
|
||||
<input
|
||||
class="max-w-80 border rounded-md !pl-8"
|
||||
placeholder="Search workers by name..."
|
||||
autocomplete="off"
|
||||
bind:value={search}
|
||||
/>
|
||||
<Search class="absolute left-2 " size={14} />
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
if ($page.url.pathname != '/user/login') {
|
||||
setUserWorkspaceStore()
|
||||
loadUser()
|
||||
UserService.refreshUserToken()
|
||||
UserService.refreshUserToken({ ifExpiringInLessThanS: 60 * 60 * 24 })
|
||||
}
|
||||
|
||||
let i = 0
|
||||
@@ -135,7 +135,8 @@
|
||||
|
||||
// every 1 hour
|
||||
if (i % 12 == 0) {
|
||||
await UserService.refreshUserToken()
|
||||
console.debug('Refreshing user token')
|
||||
await UserService.refreshUserToken({ ifExpiringInLessThanS: 60 * 60 * 24 })
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user