Skip to content

Commit a138b91

Browse files
committed
fix(nextjs): added SSR no-op on autoAnonymousLogin. onAuthStateChanged state change updates
1 parent d851cd6 commit a138b91

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/firebaseui-core/src/behaviors.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,24 @@ export function getBehavior<T extends BehaviorKey>(ui: FirebaseUIConfiguration,
4040
}
4141

4242
export function autoAnonymousLogin(): Behavior<'autoAnonymousLogin'> {
43+
/** No-op on Server render */
44+
if (typeof window === 'undefined') {
45+
console.log('[autoAnonymousLogin] SSR mode — returning noop behavior');
46+
return {
47+
autoAnonymousLogin: async (_ui) => {
48+
/** Return a placeholder user object */
49+
return { uid: 'server-placeholder' } as unknown as User;
50+
},
51+
};
52+
}
53+
4354
return {
4455
autoAnonymousLogin: async (ui) => {
4556
const auth = ui.getAuth();
46-
ui.setState('signing-in');
57+
4758
const user = await new Promise<User>((resolve) => {
4859
const unsubscribe = onAuthStateChanged(auth, (user) => {
60+
ui.setState('signing-in');
4961
if (!user) {
5062
signInAnonymously(auth);
5163
return;

0 commit comments

Comments
 (0)