sample code: ```rs #[derive(Clone)] pub struct Backend { db: Arc<D1Database>, } #[derive(Debug,

sample code:
#[derive(Clone)]
pub struct Backend {
    db: Arc<D1Database>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Credentials {
    pub username: String,
    pub password: String
}

impl Backend {
    pub fn new(db: D1Database) -> Self {
        Self {
            db: Arc::new(db)
        }
    }
}

unsafe impl Send for Backend {}
unsafe impl Sync for Backend {}

#[async_trait::async_trait]
impl AuthnBackend for Backend {
    type User = User;
    type Credentials = Credentials;
    type Error = worker::Error;

    #[worker::send]
    async fn authenticate(&self, credentials: Self::Credentials) -> Result<Option<Self::User>, Self::Error> {
        todo!()
    }

    async fn get_user(&self, user_id: &UserId<Self>) -> Result<Option<Self::User>, Self::Error>{
        todo!()
    }
}
Was this page helpful?