1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Basic current session/user query + user emails connection

This commit is contained in:
Quentin Gliech
2022-11-07 18:34:11 +01:00
parent ea1ecd5fc6
commit ac40367c5f
7 changed files with 453 additions and 10 deletions

View File

@@ -29,6 +29,10 @@ use mas_axum_utils::SessionInfo;
use sqlx::PgPool;
use tokio_stream::{Stream, StreamExt};
use self::model::{BrowserSession, User};
mod model;
pub type Schema = async_graphql::Schema<Query, Mutation, Subscription>;
pub type SchemaBuilder = async_graphql::SchemaBuilder<Query, Mutation, Subscription>;
@@ -51,14 +55,25 @@ impl Query {
#[async_graphql::Object]
impl Query {
/// A simple property which uses the DB pool and the current session
async fn username(&self, ctx: &Context<'_>) -> Result<Option<String>, async_graphql::Error> {
async fn current_session(
&self,
ctx: &Context<'_>,
) -> Result<Option<BrowserSession>, async_graphql::Error> {
let database = ctx.data::<PgPool>()?;
let session_info = ctx.data::<SessionInfo>()?;
let mut conn = database.acquire().await?;
let session = session_info.load_session(&mut conn).await?;
Ok(session.map(|s| s.user.username))
Ok(session.map(BrowserSession::from))
}
async fn current_user(&self, ctx: &Context<'_>) -> Result<Option<User>, async_graphql::Error> {
let database = ctx.data::<PgPool>()?;
let session_info = ctx.data::<SessionInfo>()?;
let mut conn = database.acquire().await?;
let session = session_info.load_session(&mut conn).await?;
Ok(session.map(User::from))
}
}