Skip to content

getCookie issue with 0.1.8 using Http #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NathanWalker opened this issue Jun 22, 2016 · 14 comments · Fixed by #321
Closed

getCookie issue with 0.1.8 using Http #305

NathanWalker opened this issue Jun 22, 2016 · 14 comments · Fixed by #321
Assignees

Comments

@NathanWalker
Copy link
Contributor

ORIGINAL EXCEPTION: Error: not implemented
ORIGINAL STACKTRACE:
Error: not implemented
    at NativeScriptDomAdapter.Parse5DomAdapter.getCookie (/data/data/org.nativescript.nativescriptweather/files/app/tns_modules/@angular/platform-server/src/parse5_adapter.js:612:68)

Fixed by #286

@vakrilov
Copy link
Contributor

PR merged

@vakrilov
Copy link
Contributor

Btw, the quick and dirty workaround until the fix is live is to add the not implemented method(somehere in the main.ts):

// HACK - patch dom adapter
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
(<any>Parse5DomAdapter).prototype.getCookie = function (name) { return null; };

@samarthagarwal
Copy link

Is it fixed yet?

@vakrilov
Copy link
Contributor

Yes - version 0.2.0 has the fix

@SamVerschueren
Copy link

SamVerschueren commented Jun 30, 2016

This is odd, are you sure this is fixed? This is what I did to confirm.

  1. Install nativescript
$ npm install -g nativescript
$ tns --version
2.1.0
  1. Create a new fresh project
$ tns create foobar --ng
$ cd foobar
  1. Replace the code in app.component.ts with this piece
import {Component} from "@angular/core";
import {HTTP_PROVIDERS, Http, Headers} from "@angular/http";
import {Observable} from "rxjs/Rx";

@Component({
    selector: "my-app",
    templateUrl: "app.component.html",
    providers: [HTTP_PROVIDERS]
})
export class AppComponent {

    constructor(private _http: Http) {

    }

    public onTap() {
        this.createUser()
            .subscribe(
                () => alert('Your account was successfully created.'),
                () => alert('Unfortunately we were unable to create your account.')
            );
    }

    private createUser() {
        const headers = new Headers();
        headers.append("Content-Type", "application/json");

        const body = JSON.stringify({
            Username: '[email protected]',
            Email: '[email protected]',
            Password: 'foobar'
        });

        return this._http.post('https://api.everlive.com/v1/GWfRtXi1Lwt4jcqK/Users', body, {headers}).catch(this.handleErrors);
    }

    handleErrors(error: Response) {
        console.log(JSON.stringify(error.json()));
        return Observable.throw(error);
    }
}
  1. Start the project
$ tns platform add ios
$ tns run ios --emulator
  1. Press the TAP button
    App will crash

By adding the "hack", it works. The nativescript-angular version is 0.2.0.

@vakrilov
Copy link
Contributor

vakrilov commented Jul 1, 2016

Confirmed - I'm still getting the crash. Reopening for investigation.

@vakrilov vakrilov reopened this Jul 1, 2016
@vakrilov
Copy link
Contributor

vakrilov commented Jul 1, 2016

OK, some updates:
The fix form @NathanWalker if you pass HTTP_PROVIDERS in the nativeScriptBootstrap function. It provides a custom NSXSRFStrategy that does not use cookies - so no crash.

However, if you add HTTP_PROVIDERS at component level (as in the @SamVerschueren's example) the built-in angular XSRFStrategy is used. It depends on cookies and causes the crash. The "load local files" goodies form #249 will also not work in this case.

For now: You can just add HTTP_PROVIDERS in the bootstrap and everything should work fine.

General Fix Proposal: Export NS_HTTP_PROVIDERS that can be provided at component level and provide the right XHR related dependencies.

@vakrilov vakrilov self-assigned this Jul 1, 2016
@NathanWalker
Copy link
Contributor Author

@vakrilov working up PR to handle this now. Curious your opinion:
Should we still auto push in NS_HTTP_PROVIDERS in appProviders or should we just document that the user should instead import those and use them instead of HTTP_PROVIDERS? I could go either way.

@NathanWalker
Copy link
Contributor Author

@samarthagarwal @SamVerschueren Final fix is here: #321

Once that lands, you can use this guide: https://github.com/NativeScript/nativescript-angular/wiki/Http

@vakrilov
Copy link
Contributor

vakrilov commented Jul 1, 2016

👍

@SamVerschueren
Copy link

I'm not familiar with the {N} core or the technical implementation whatsoever, but is it technically not possible to patch the @angular/http HTTP_PROVIDERS to just work without introducing NS_HTTP_PROVIDERS?

@tjvantoll
Copy link

I'm not familiar with the {N} core or the technical implementation whatsoever, but is it technically not possible to patch the @angular/http HTTP_PROVIDERS to just work without introducing NS_HTTP_PROVIDERS?

Agreed here, and I think this is going to confuse a fair number of people, especially considering the error message doesn’t point you in the right direction at all.

If this is indeed a necessity, is there anything we can do to point people in the right direction when they use HTTP_PROVIDERS at the component level?

cc @NathanWalker @vakrilov

@vakrilov
Copy link
Contributor

vakrilov commented Jul 6, 2016

Agree - making HTTP_PROVIDERS just work would be the easiest option to use.

However, I don't see how this can be done, because of the way HTTP_PROVIDERS are defined. The XSRFStrategy is the thing that we want to override but because it is defined inside the HTTP_PROVIDERS if you want to tell the DI to use another strategy - you should do it after including HTTP_PROVIDERS. That's how its done in the NS_HTTP_PROVIDERS.

One more argument for the NS_HTTP_PROVIDERS is that we actually provide extended Http implementation - more on that #286.

@burkeholland
Copy link

I hit this after upgrading from 0.2.0 to 0.3.0. I've always been bootstrapping with HTTP_PROVIDERS. Switching to NS_HTTP_PROVIDERS fixed the issue.

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

Successfully merging a pull request may close this issue.

6 participants