Skip to content

Commit ef3736b

Browse files
committed
add auth delete test
1 parent 505b745 commit ef3736b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/auth/test/integration/flows/firebaseserverapp.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,55 @@ describe('Integration test: Auth FirebaseServerApp tests', () => {
290290
expect(serverAppAuth.currentUser?.displayName).to.equal(newDisplayName);
291291
}
292292
});
293+
294+
it('can sign out of main auth and still use server auth', async () => {
295+
if (isBrowser()) {
296+
return;
297+
}
298+
const userCred = await signInAnonymously(auth);
299+
expect(auth.currentUser).to.eq(userCred.user);
300+
301+
const user = userCred.user;
302+
expect(user).to.equal(auth.currentUser);
303+
expect(user.uid).to.be.a('string');
304+
expect(user.displayName).to.be.null;
305+
306+
const authIdToken = await user.getIdToken();
307+
const firebaseServerAppSettings = { authIdToken };
308+
309+
const serverApp = initializeServerApp(
310+
auth.app.options,
311+
firebaseServerAppSettings
312+
);
313+
serverAppAuth = getAuth(serverApp);
314+
let numberServerLogins = 0;
315+
onAuthStateChanged(serverAppAuth, serverAuthUser => {
316+
if (serverAuthUser) {
317+
numberServerLogins++;
318+
expect(serverAppAuth).to.not.be.null;
319+
expect(user.uid).to.be.equal(serverAuthUser.uid);
320+
expect(user.displayName).to.be.null;
321+
if (serverAppAuth) {
322+
expect(serverAppAuth.currentUser).to.equal(serverAuthUser);
323+
}
324+
}
325+
});
326+
327+
await signOut(auth);
328+
await new Promise(resolve => {
329+
setTimeout(resolve, signInWaitDuration);
330+
});
331+
332+
expect(serverAppAuth.currentUser).to.not.be.null;
333+
334+
if (serverAppAuth.currentUser) {
335+
await serverAppAuth.currentUser.reload();
336+
}
337+
338+
expect(numberServerLogins).to.equal(1);
339+
expect(serverAppAuth).to.not.be.null;
340+
if (serverAppAuth) {
341+
expect(serverAppAuth.currentUser).to.not.be.null;
342+
}
343+
});
293344
});

0 commit comments

Comments
 (0)