feat: Add me_query API (#940)

* feat: add me query

* fix compile

* update schema
add-signin-page
Eric 2023-12-04 12:20:05 +08:00 committed by GitHub
parent 305b3f913b
commit 870638cbbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 7 deletions

View File

@ -17,15 +17,15 @@ type Mutation {
deleteInvitation(id: Int!): Int! deleteInvitation(id: Int!): Int!
} }
type VerifyTokenResponse {
claims: Claims!
}
type UserInfo { type UserInfo {
email: String! email: String!
isAdmin: Boolean! isAdmin: Boolean!
} }
type VerifyTokenResponse {
claims: Claims!
}
type Claims { type Claims {
exp: Float! exp: Float!
iat: Float! iat: Float!
@ -37,6 +37,7 @@ type Query {
registrationToken: String! registrationToken: String!
isAdminInitialized: Boolean! isAdminInitialized: Boolean!
invitations: [Invitation!]! invitations: [Invitation!]!
me: UserInfo!
} }
type Invitation { type Invitation {

View File

@ -145,7 +145,7 @@ impl VerifyTokenResponse {
} }
} }
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, GraphQLObject)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, GraphQLObject)]
pub struct UserInfo { pub struct UserInfo {
email: String, email: String,
is_admin: bool, is_admin: bool,

View File

@ -17,7 +17,7 @@ use self::{
worker::WorkerService, worker::WorkerService,
}; };
use crate::schema::{ use crate::schema::{
auth::{RegisterResponse, TokenAuthResponse, VerifyTokenResponse}, auth::{RegisterResponse, TokenAuthResponse, UserInfo, VerifyTokenResponse},
worker::Worker, worker::Worker,
}; };
@ -91,6 +91,13 @@ impl Query {
"Only admin is able to query invitations", "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)] #[derive(Default)]

View File

@ -23,7 +23,7 @@ lazy_static! {
); );
"# "#
) )
.down("DROP TABLE registeration_token"), .down("DROP TABLE registration_token"),
M::up( M::up(
r#" r#"
CREATE TABLE users ( CREATE TABLE users (