Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add me_query API #940

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion ee/tabby-webserver/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use self::{
worker::WorkerService,
};
use crate::schema::{
auth::{RegisterResponse, TokenAuthResponse, VerifyTokenResponse},
auth::{RegisterResponse, TokenAuthResponse, UserInfo, VerifyTokenResponse},
worker::Worker,
};

Expand Down Expand Up @@ -91,6 +91,13 @@ impl Query {
"Only admin is able to query invitations",
))
}

async fn me(ctx: &Context) -> Result<UserInfo> {
if let Some(claims) = &ctx.claims {
return Ok(claims.user_info().to_owned());
}
Err(CoreError::Unauthorized("Not logged in"))
}
}

#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lazy_static! {
);
"#
)
.down("DROP TABLE registeration_token"),
.down("DROP TABLE registration_token"),
M::up(
r#"
CREATE TABLE users (
Expand Down
Loading