RaphaelJenni / FirebaseUI-Angular

A wrapper for FirebaseUI in Angular
Apache License 2.0
298 stars 69 forks source link

Don't reference window object directly #109

Closed SachinShekhar closed 4 years ago

SachinShekhar commented 4 years ago

I can see here in this service that you've referenced window object directly:

@Injectable()
export class FirebaseuiAngularLibraryService {
  public firebaseUiInstance: firebaseui.auth.AuthUI;

  constructor(angularFireAuth: AngularFireAuth) {
    // store the firebaseui instance on the window object to prevent double initialization
    if (!(<any>window).firebaseUiInstance) {
      (<any>window).firebaseUiInstance = new firebaseui.auth.AuthUI(angularFireAuth.auth);
    }
    this.firebaseUiInstance = (<any>window).firebaseUiInstance as firebaseui.auth.AuthUI;
  }
}

This is not a standard Angular practice. To enforce singleton behavior, there's Dependency Injection system in place. See this.

My Problem: Because of this, SSR (Angular Universal) is throwing error.

Consider it as a bug and/or feature request, but please remove window reference.

SachinShekhar commented 4 years ago

It seems that this won't fix my issue because you are merely a wrapper and firebaseui itself is the main offender to use global window object.

coleridge72 commented 2 years ago

For anyone else stuck on this (I was) - I got round it by creating a separate module that contains all the sign-in logic and then used angular lazy-loading in the router to access this module.

In the server.ts file I also had make this route served by the browser.

  server.get('/login', function (req, res) {
    res.sendFile(join(distFolder, 'browser', 'index.html'));
 });