@@ -81,6 +81,8 @@ import { _logWarn } from '../util/log';
81
81
import { _getPasswordPolicy } from '../../api/password_policy/get_password_policy' ;
82
82
import { PasswordPolicyInternal } from '../../model/password_policy' ;
83
83
import { PasswordPolicyImpl } from './password_policy_impl' ;
84
+ import { getAccountInfo } from '../../api/account_management/account' ;
85
+ import { UserImpl } from '../user/user_impl' ;
84
86
85
87
interface AsyncAction {
86
88
( ) : Promise < void > ;
@@ -92,6 +94,28 @@ export const enum DefaultConfig {
92
94
API_SCHEME = 'https'
93
95
}
94
96
97
+
98
+ async function loadUserFromIdToken (
99
+ auth : AuthInternal ,
100
+ idToken : string
101
+ ) : Promise < UserInternal | null > {
102
+ try {
103
+ const response = await getAccountInfo ( auth , { idToken } ) ;
104
+ const user = await UserImpl . _fromGetAccountInfoResponse (
105
+ auth ,
106
+ response ,
107
+ idToken
108
+ ) ;
109
+ return user ;
110
+ } catch ( err ) {
111
+ console . warn (
112
+ 'FirebaseServerApp could not login user with provided authIdToken: ' ,
113
+ err
114
+ ) ;
115
+ return null ;
116
+ }
117
+ }
118
+
95
119
export class AuthImpl implements AuthInternal , _FirebaseService {
96
120
currentUser : User | null = null ;
97
121
emulatorConfig : EmulatorConfig | null = null ;
@@ -174,10 +198,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
174
198
}
175
199
}
176
200
177
- // Skip loading users from persistence in FirebaseServerApp Auth instances.
178
- if ( ! _isFirebaseServerApp ( this . app ) ) {
179
- await this . initializeCurrentUser ( popupRedirectResolver ) ;
180
- }
201
+ await this . initializeCurrentUser ( popupRedirectResolver ) ;
181
202
182
203
this . lastNotifiedUid = this . currentUser ?. uid || null ;
183
204
@@ -248,6 +269,21 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
248
269
}
249
270
}
250
271
272
+ if ( _isFirebaseServerApp ( this . app ) ) {
273
+ if ( this . app . settings . authIdToken !== undefined ) {
274
+ const idToken = this . app . settings . authIdToken ;
275
+ // Start the auth operation in the next tick to allow a moment for the customer's app to
276
+ // attach an emulator, if desired.
277
+ setTimeout ( ( ) =>
278
+ void loadUserFromIdToken ( this , idToken ) . then ( user =>
279
+ void this . directlySetCurrentUser ( user )
280
+ ) ,
281
+ 0
282
+ ) ;
283
+ return ;
284
+ }
285
+ }
286
+
251
287
// If no user in persistence, there is no current user. Set to null.
252
288
if ( ! futureCurrentUser ) {
253
289
return this . directlySetCurrentUser ( null ) ;
0 commit comments