better_auth_core/config/
scalars.rs1use super::{
2 AccountConfig, AccountLinkingConfig, AdvancedDatabaseConfig, ApiErrorConfig, AuthConfig,
3 CrossSubDomainConfig, IpAddressConfig, SessionConfig, TrustedValues, VerificationConfig,
4};
5use chrono::Duration;
6
7impl SessionConfig {
8 pub fn expires_in(&self) -> Duration {
10 self.expires_in
11 .filter(|age| !age.is_zero())
12 .unwrap_or_else(|| Duration::days(7))
13 }
14
15 pub fn update_age(&self) -> Duration {
17 self.update_age.unwrap_or_else(|| Duration::days(1))
18 }
19
20 pub fn disable_session_refresh(&self) -> bool {
22 self.disable_session_refresh.unwrap_or(false)
23 }
24
25 pub fn store_session_in_database(&self) -> bool {
27 self.store_session_in_database.unwrap_or(false)
28 }
29
30 pub fn preserve_session_in_database(&self) -> bool {
32 self.preserve_session_in_database.unwrap_or(false)
33 }
34}
35
36impl AccountConfig {
37 pub fn update_account_on_sign_in(&self) -> bool {
39 self.update_account_on_sign_in.unwrap_or(true)
40 }
41
42 pub fn encrypt_oauth_tokens(&self) -> bool {
44 self.encrypt_oauth_tokens.unwrap_or(false)
45 }
46}
47
48impl AccountLinkingConfig {
49 pub fn enabled(&self) -> bool {
51 self.enabled.unwrap_or(true)
52 }
53
54 pub fn allow_unlinking_all(&self) -> bool {
56 self.allow_unlinking_all.unwrap_or(false)
57 }
58
59 pub fn update_user_info_on_link(&self) -> bool {
61 self.update_user_info_on_link.unwrap_or(false)
62 }
63}
64
65impl VerificationConfig {
66 pub fn disable_cleanup(&self) -> bool {
68 self.disable_cleanup.unwrap_or(false)
69 }
70}
71
72impl ApiErrorConfig {
73 pub fn throw_errors(&self) -> bool {
75 self.throw_errors.unwrap_or(false)
76 }
77}
78
79impl IpAddressConfig {
80 pub fn headers(&self) -> impl Iterator<Item = &str> {
82 self.headers
83 .iter()
84 .flatten()
85 .map(String::as_str)
86 .chain(self.headers.is_none().then_some("x-forwarded-for"))
87 }
88
89 pub fn disable_ip_tracking(&self) -> bool {
91 self.disable_ip_tracking.unwrap_or(false)
92 }
93}
94
95impl CrossSubDomainConfig {
96 pub fn enabled(&self) -> bool {
98 self.enabled.unwrap_or(false)
99 }
100}
101
102impl AdvancedDatabaseConfig {
103 pub fn generate_id(&self) -> &crate::id::IdGeneration {
105 self.generate_id
106 .as_ref()
107 .unwrap_or(&crate::id::IdGeneration::Random)
108 }
109}
110
111static EMPTY_TRUSTED_VALUES: TrustedValues = TrustedValues::Static(Vec::new());
112
113impl AuthConfig {
114 pub(crate) fn trusted_origin_values(&self) -> &TrustedValues {
115 self.trusted_origins
116 .as_ref()
117 .unwrap_or(&EMPTY_TRUSTED_VALUES)
118 }
119}
120
121impl AccountLinkingConfig {
122 pub(crate) fn trusted_provider_values(&self) -> &TrustedValues {
123 self.trusted_providers
124 .as_ref()
125 .unwrap_or(&EMPTY_TRUSTED_VALUES)
126 }
127}