Skip to main content

authx_plugins/
base.rs

1use async_trait::async_trait;
2use axum::Router;
3
4use authx_core::{error::Result, models::User};
5
6/// Every auth feature is a Plugin.
7///
8/// Plugins register routes, react to lifecycle events, and can extend the
9/// JWT payload and resolved Identity. The `setup` method is called once
10/// during `Auth` initialization — use it to validate config and wire event
11/// subscriptions.
12#[async_trait]
13pub trait Plugin: Send + Sync + 'static {
14    fn name(&self) -> &'static str;
15
16    fn dependencies(&self) -> Vec<&'static str> {
17        vec![]
18    }
19
20    async fn setup(&mut self) -> Result<()> {
21        Ok(())
22    }
23
24    fn routes(&self) -> Option<Router> {
25        None
26    }
27
28    async fn on_user_created(&self, _user: &User) -> Result<()> {
29        Ok(())
30    }
31
32    fn extend_token_payload(&self, payload: &mut serde_json::Value, _user: &User) {
33        let _ = payload;
34    }
35}