tauri_plugin_google_auth/
lib.rs

1use tauri::{
2    plugin::{Builder, TauriPlugin},
3    Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(desktop)]
9mod desktop;
10#[cfg(mobile)]
11mod mobile;
12
13mod commands;
14mod error;
15mod models;
16
17pub use error::{Error, Result};
18
19#[cfg(desktop)]
20use desktop::GoogleAuth;
21#[cfg(mobile)]
22use mobile::GoogleAuth;
23
24/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the google-auth APIs.
25pub trait GoogleAuthExt<R: Runtime> {
26    fn google_auth(&self) -> &GoogleAuth<R>;
27}
28
29impl<R: Runtime, T: Manager<R>> crate::GoogleAuthExt<R> for T {
30    fn google_auth(&self) -> &GoogleAuth<R> {
31        self.state::<GoogleAuth<R>>().inner()
32    }
33}
34
35/// Initializes the plugin.
36pub fn init<R: Runtime>() -> TauriPlugin<R> {
37    Builder::new("google-auth")
38        .invoke_handler(tauri::generate_handler![
39            commands::sign_in,
40            commands::sign_out,
41            commands::refresh_token
42        ])
43        .setup(|app, api| {
44            #[cfg(mobile)]
45            let google_auth = mobile::init(app, api)?;
46            #[cfg(desktop)]
47            let google_auth = desktop::init(app, api)?;
48            app.manage(google_auth);
49            Ok(())
50        })
51        .build()
52}