Skip to main content

Mountain/Track/Effect/CreateEffectForRequest/
Authentication.rs

1use CommonLibrary::IPC::DTO::ProxyTarget::ProxyTarget;
2use serde_json::{Value, json};
3use tauri::Runtime;
4
5use crate::{
6	Track::Effect::{
7		CreateEffectForRequest::Utilities::{Params::string_at, Proxy::proxy_cocoon},
8		MappedEffectType::MappedEffect,
9	},
10	dev_log,
11};
12
13pub fn CreateEffect<R:Runtime>(MethodName:&str, Parameters:Value) -> Option<Result<MappedEffect, String>> {
14	match MethodName {
15		"Authentication.GetSession" => {
16			crate::effect!(run_time, {
17				let provider_id = string_at(&Parameters, 0);
18
19				let scopes = Parameters.get(1).cloned().unwrap_or(json!([]));
20
21				let options = Parameters.get(2).cloned().unwrap_or(json!({}));
22
23				proxy_cocoon(
24					&run_time,
25					ProxyTarget::ExtHostAuthentication,
26					"getSession",
27					json!([provider_id, scopes, options]),
28					5000,
29				)
30				.await
31				.or_else(|error| {
32					dev_log!(
33						"ipc",
34						"warn: [Authentication.GetSession] extension did not answer ({:?}); returning null",
35						error
36					);
37
38					Ok(json!(null))
39				})
40			})
41		},
42
43		"Authentication.GetAccounts" => {
44			crate::effect!(run_time, {
45				let provider_id = string_at(&Parameters, 0);
46
47				proxy_cocoon(
48					&run_time,
49					ProxyTarget::ExtHostAuthentication,
50					"getAccounts",
51					json!([provider_id]),
52					5000,
53				)
54				.await
55				.or_else(|error| {
56					dev_log!(
57						"ipc",
58						"warn: [Authentication.GetAccounts] extension did not answer ({:?}); returning []",
59						error
60					);
61
62					Ok(json!([]))
63				})
64			})
65		},
66
67		_ => None,
68	}
69}