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!
}
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 {

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 {
email: String,
is_admin: bool,

View File

@ -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<UserInfo> {
if let Some(claims) = &ctx.claims {
return Ok(claims.user_info().to_owned());
}
Err(CoreError::Unauthorized("Not logged in"))
}
}
#[derive(Default)]

View File

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