From 8b092b696887b667cde49ef86f37c1b8596622a5 Mon Sep 17 00:00:00 2001 From: darknight Date: Sun, 3 Dec 2023 16:24:00 +0800 Subject: [PATCH 1/3] feat: add me query --- ee/tabby-webserver/src/schema/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ee/tabby-webserver/src/schema/mod.rs b/ee/tabby-webserver/src/schema/mod.rs index 459a4540ce3b..4a0057d1be6e 100644 --- a/ee/tabby-webserver/src/schema/mod.rs +++ b/ee/tabby-webserver/src/schema/mod.rs @@ -17,7 +17,7 @@ use self::{ worker::WorkerService, }; use crate::schema::{ - auth::{RegisterResponse, TokenAuthResponse, VerifyTokenResponse}, + auth::{RegisterResponse, TokenAuthResponse, UserInfo, VerifyTokenResponse}, worker::Worker, }; @@ -91,6 +91,13 @@ impl Query { "Only admin is able to query invitations", )) } + + async fn me(ctx: &Context) -> Result { + if let Some(claims) = &ctx.claims { + return Ok(claims.user_info().clone()); + } + Err(CoreError::Unauthorized("Not logged in")) + } } #[derive(Default)] From dc2340ecf6e6e406a68d1e6cffd1e81707a6adbf Mon Sep 17 00:00:00 2001 From: darknight Date: Sun, 3 Dec 2023 16:39:40 +0800 Subject: [PATCH 2/3] fix compile --- ee/tabby-webserver/src/schema/auth.rs | 2 +- ee/tabby-webserver/src/schema/mod.rs | 2 +- ee/tabby-webserver/src/service/db.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ee/tabby-webserver/src/schema/auth.rs b/ee/tabby-webserver/src/schema/auth.rs index a8767ba2536e..82a1f23c8776 100644 --- a/ee/tabby-webserver/src/schema/auth.rs +++ b/ee/tabby-webserver/src/schema/auth.rs @@ -145,7 +145,7 @@ impl VerifyTokenResponse { } } -#[derive(Debug, Default, PartialEq, Serialize, Deserialize, GraphQLObject)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, GraphQLObject)] pub struct UserInfo { email: String, is_admin: bool, diff --git a/ee/tabby-webserver/src/schema/mod.rs b/ee/tabby-webserver/src/schema/mod.rs index 4a0057d1be6e..444713e3522e 100644 --- a/ee/tabby-webserver/src/schema/mod.rs +++ b/ee/tabby-webserver/src/schema/mod.rs @@ -94,7 +94,7 @@ impl Query { async fn me(ctx: &Context) -> Result { if let Some(claims) = &ctx.claims { - return Ok(claims.user_info().clone()); + return Ok(claims.user_info().to_owned()); } Err(CoreError::Unauthorized("Not logged in")) } diff --git a/ee/tabby-webserver/src/service/db.rs b/ee/tabby-webserver/src/service/db.rs index 80a1ec5082cc..b456e8376960 100644 --- a/ee/tabby-webserver/src/service/db.rs +++ b/ee/tabby-webserver/src/service/db.rs @@ -23,7 +23,7 @@ lazy_static! { ); "# ) - .down("DROP TABLE registeration_token"), + .down("DROP TABLE registration_token"), M::up( r#" CREATE TABLE users ( From b401516e5e634656f3ecda8c690eea49193b1760 Mon Sep 17 00:00:00 2001 From: darknight Date: Sun, 3 Dec 2023 17:42:12 +0800 Subject: [PATCH 3/3] update schema --- ee/tabby-webserver/graphql/schema.graphql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ee/tabby-webserver/graphql/schema.graphql b/ee/tabby-webserver/graphql/schema.graphql index b30a8f327b58..cdd700cf7b9f 100644 --- a/ee/tabby-webserver/graphql/schema.graphql +++ b/ee/tabby-webserver/graphql/schema.graphql @@ -17,15 +17,15 @@ type Mutation { deleteInvitation(id: Int!): Int! } +type VerifyTokenResponse { + claims: Claims! +} + type UserInfo { email: String! isAdmin: Boolean! } -type VerifyTokenResponse { - claims: Claims! -} - type Claims { exp: Float! iat: Float! @@ -37,6 +37,7 @@ type Query { registrationToken: String! isAdminInitialized: Boolean! invitations: [Invitation!]! + me: UserInfo! } type Invitation {