Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

stateService.ts:530 TypeError: Cannot read property 'getCookie' of null #71

Open
jelling opened this issue Feb 19, 2017 · 4 comments
Open

Comments

@jelling
Copy link

jelling commented Feb 19, 2017

I'm attempting to use the angular 2 sdk but receive the following error:

stateService.ts:530 TypeError: Cannot read property 'getCookie' of null
at CookieXSRFStrategy.configureRequest (xhr_backend.js:206)
at XHRBackend.createConnection (xhr_backend.js:261)
at httpRequest (http.js:24)
at StormpathHttp.Http.request (http.js:133)
at StormpathHttp.request (stormpath.http.ts:44)
at StormpathHttp.Http.get (http.js:147)
at Stormpath.getAccount (stormpath.service.ts:116)
at new Stormpath (stormpath.service.ts:103)
at AppModuleInjector.get (/AppModule/module.ngfactory.js:239)
at AppModuleInjector.getInternal (/AppModule/module.ngfactory.js:474)
at AppModuleInjector.NgModuleInjector.get (core.umd.js:9003)
at MergeInjector.get (mergeInjector.ts:31)
at ReflectiveInjector_.getByKeyDefault (core.umd.js:3434)
at ReflectiveInjector
.getByKey (core.umd.js:3384)
at ReflectiveInjector
.get (core.umd.js:3144)

Here's my typescript component:

import {
  Component,
  Inject
} from "@angular/core";

import { Stormpath, Account } from 'angular-stormpath';
import { Observable } from 'rxjs';

@Component({
  selector: "checkout",
  templateUrl: "onboard/templates/onboard.html",
  styleUrls: ["onboard/styles/onboard.css"]
})
export class Onboard {
  name: string = `yo, I"m your component :D`;

  // TODO: move all of this stormpath stuff to a component that will be the root component for customer area || entire app
  private user$: Observable<Account | boolean>;
  private loggedIn$: Observable<boolean>;
  private login: boolean;
  private register: boolean;
 
  constructor(public stormpath: Stormpath) {
  }
 
  ngOnInit() {
    this.login = true;
    this.register = false;
    this.user$ = this.stormpath.user$;
    this.loggedIn$ = this.user$.map(user => !!user);
  }
 
  showLogin() {
    this.login = !(this.register = false);
  }
 
  showRegister() {
    this.register = !(this.login = false);
  }
 
  logout() {
    this.stormpath.logout();
  }

}

Any ideas? I'm following the getting started tutorial here: https://stormpath.com/blog/angular-2-user-authentication

@mraible
Copy link
Contributor

mraible commented Feb 20, 2017

What version of Angular are you using? It works best if you can use 2.3.x or greater.

@jelling
Copy link
Author

jelling commented Feb 20, 2017 via email

@mraible
Copy link
Contributor

mraible commented Feb 20, 2017

What build system are you using? I know how to make things work with Webpack 2, and might be able to help with SystemJS.

@jelling
Copy link
Author

jelling commented Feb 20, 2017

I'm using SystemJS. Here's the config.js:

System.config({
  defaultJSExtensions: true,
  paths: {
    // paths serve as alias
    'npm:': './'
  },
  // map tells the System loader where to look for things
  map: {
    // our app is within the app folder
    app: 'app',

    // angular bundles
    '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
    '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
    '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
    '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
    '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

    // other libraries
    'rxjs':                       'npm:rxjs',
    'ui-router-ng2': 'https://unpkg.com/ui-router-ng2@1.0.0-beta.3/_bundles/ui-router-ng2.js',
    'angular-stormpath': 'npm:angular-stormpath/dist/umd/stormpath-sdk-angular.js'              
  }
});

I believe the stormpath-sdk-angular.js is being loaded because we can see StormpathHttp.Http.request() in the stack trace above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants