Skip to content

Bug and solution: angularfire2 auth not working with angular universal #1270

Closed
@hiepxanh

Description

@hiepxanh

Thanks for @katowulf advice.

Think you found a bug?

Yes, I found a bug in angular auth when running on nodejs with angular universal universal starter repo

Version info

  • @angular/ 4.2.4
  • firebase: 4.5.0
  • angularfire2: 5.0.rc-2

Steps to set up and reproduce

  1. clone universal starter repo
  2. add firebase module to app module
  3. add auth in app.component.ts
    image
  4. run npm run build:dynamic && npm run serve:dynamic
  5. get error

I make an sample repository here to view my code

ERROR

Failing test unit, Plunkr, or JSFiddle demonstrating the problem
image

Expected behavior

In my opinion, angularfire2 already have XMLHttpRequest library, but maybe some problem when bootstrap. Maybe you can fix this bug and I don't have to add XMLHttpRequest manually

Actual behavior

get error with XMLHttpRequest.
Solution: I add this on top, error gone.

// server.ts file
(global as any).XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
// your code next...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions