forked from jmug/stoatchat
chore: migrate authifier into codebase (#658)
Co-authored-by: izzy <me@insrt.uk> Signed-off-by: Zomatree <me@zomatree.live> Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use authifier::{
|
||||
models::{Session, WebPushSubscription},
|
||||
Authifier,
|
||||
};
|
||||
use revolt_database::{Database, Session};
|
||||
use revolt_models::v0;
|
||||
use revolt_result::{create_database_error, Result};
|
||||
use rocket::{serde::json::Json, State};
|
||||
use rocket_empty::EmptyResponse;
|
||||
@@ -14,13 +12,13 @@ use rocket_empty::EmptyResponse;
|
||||
#[openapi(tag = "Web Push")]
|
||||
#[post("/subscribe", data = "<data>")]
|
||||
pub async fn subscribe(
|
||||
authifier: &State<Authifier>,
|
||||
db: &State<Database>,
|
||||
mut session: Session,
|
||||
data: Json<WebPushSubscription>,
|
||||
data: Json<v0::WebPushSubscription>,
|
||||
) -> Result<EmptyResponse> {
|
||||
session.subscription = Some(data.into_inner());
|
||||
session.subscription = Some(data.into_inner().into());
|
||||
session
|
||||
.save(authifier)
|
||||
.save(db)
|
||||
.await
|
||||
.map(|_| EmptyResponse)
|
||||
.map_err(|_| create_database_error!("save", "session"))
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use authifier::{models::Session, Authifier};
|
||||
|
||||
use revolt_database::{Database, Session};
|
||||
use revolt_result::{create_database_error, Result};
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
@@ -10,13 +9,10 @@ use rocket::State;
|
||||
/// Remove the Web Push subscription associated with the current session.
|
||||
#[openapi(tag = "Web Push")]
|
||||
#[post("/unsubscribe")]
|
||||
pub async fn unsubscribe(
|
||||
authifier: &State<Authifier>,
|
||||
mut session: Session,
|
||||
) -> Result<EmptyResponse> {
|
||||
pub async fn unsubscribe(db: &State<Database>, mut session: Session) -> Result<EmptyResponse> {
|
||||
session.subscription = None;
|
||||
session
|
||||
.save(authifier)
|
||||
.save(db)
|
||||
.await
|
||||
.map(|_| EmptyResponse)
|
||||
.map_err(|_| create_database_error!("save", "session"))
|
||||
|
||||
Reference in New Issue
Block a user