bevy_gotrue/
client.rs

1use bevy::{
2    ecs::system::{Commands, Resource, SystemId},
3    prelude::In,
4};
5use ehttp::Headers;
6
7use crate::{AuthCreds, Builder};
8
9#[derive(Resource, Debug)]
10pub struct Client {
11    pub sign_in: SystemId<In<AuthCreds>>,
12    pub endpoint: String,
13    pub headers: Headers,
14    pub access_token: Option<String>,
15}
16
17impl Client {
18    pub fn builder(&self) -> Builder {
19        Builder {
20            url: self.endpoint.clone(),
21            headers: self.headers.clone(),
22        }
23    }
24    pub fn insert_header(&mut self, key: impl ToString, value: impl ToString) -> &mut Self {
25        self.headers.insert(key, value);
26        self
27    }
28    /// Returns a URL for provider oauth flow
29    pub fn get_url_for_provider(&self, provider: &str) -> String {
30        format!("{}/authorize?provider={}", self.endpoint, provider)
31    }
32    pub fn sign_in(&self, commands: &mut Commands, creds: AuthCreds) {
33        commands.run_system_with_input(self.sign_in, creds)
34    }
35}