feat: support rauth events

feat: add platform user wipe event
This commit is contained in:
Paul Makles
2023-01-20 15:43:45 +00:00
parent cf9c0bc5e1
commit fed1da72fd
8 changed files with 58 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-delta"
version = "0.5.5"
version = "0.5.6"
license = "AGPL-3.0-or-later"
authors = ["Paul Makles <paulmakles@gmail.com>"]
edition = "2018"
@@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s
# web
rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] }
rocket_empty = { version = "0.1.1", features = ["schema"] }
rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "195f1703cc4c57be01a39f465296cab4e22524b3" }
rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.2" }
# spec generation
schemars = "0.8.8"

View File

@@ -10,7 +10,9 @@ extern crate lazy_static;
pub mod routes;
pub mod util;
use revolt_quark::rauth::RAuth;
use async_std::channel::unbounded;
use revolt_quark::events::client::EventV1;
use revolt_quark::rauth::{RAuth, RAuthEvent};
use revolt_quark::DatabaseInfo;
#[launch]
@@ -25,13 +27,33 @@ async fn rocket() -> _ {
let db = DatabaseInfo::Auto.connect().await.unwrap();
db.migrate_database().await.unwrap();
// Setup rAuth event channel
let (sender, receiver) = unbounded();
// Setup rAuth
let rauth = RAuth {
database: db.clone().into(),
config: revolt_quark::util::rauth::config(),
event_channel: Some(sender),
};
// Launch background task workers.
// Launch a listener for rAuth events
async_std::task::spawn(async move {
while let Ok(event) = receiver.recv().await {
match &event {
RAuthEvent::CreateSession { .. } | RAuthEvent::CreateAccount { .. } => {
EventV1::Auth(event).global().await
}
RAuthEvent::DeleteSession { user_id, .. }
| RAuthEvent::DeleteAllSessions { user_id, .. } => {
let id = user_id.to_string();
EventV1::Auth(event).private(id).await
}
}
}
});
// Launch background task workers
async_std::task::spawn(revolt_quark::tasks::start_workers(db.clone()));
// Configure CORS