GithubHelp home page GithubHelp logo

ng2-cookies's People

Contributors

aboodz avatar bigous avatar carcamano avatar etwillbefine avatar josx avatar mhoekveen avatar sasidhar avatar sod avatar ste4net avatar tyxz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng2-cookies's Issues

It seems that it doesn't save all cookies

Hey Guys,

Could it be that your library only takes the last 'set-cookie' object from the header?
I've discovered the following problem: The response header from the login function of the site I'm calling has two set-cookie objects:

set-cookie:id=c90ee0f20c1ef9c5995894321a6dc518
set-cookie:ict-lb-oracle=orab1

But If i'm calling Cookie.getAll(), i only get the second cookie. Can i do anything to fix it?

Kind Regards,
Matthias

Publish a new version to npm

The current version on npm is outdated and causes some problems with the latest build systems (webpack 3+), can we publish a new version with the latest changes?

documentation doesn't cover api

Please update the examples to include the date, path and domain options. I will happily do this but can't readily figure out how to edit the wiki directly. Thanks!

Duplicate Cookies

I'm having an issue where certain routes of my application have multiple cookies by the same name. This only happens on certain routes, when you navigate away from them the duplicate cookie (with a different value in my case) disappears.

I've looked through the source code and set() just applies the cookie using document.cookie which I don't believe checks for duplicates, however when I attempted to apply duplicates intentionally calling set() twice with different values, only the latest value persisted.

I can't figure out if this is a common issue (no other issues mention it) and if delete() needs to be called prior to updating the cookie value. I'm also not sure why it only occurs on a single route when the a path argument isn't passed when calling set().

Work with AOT

To work properly with AOT (without having to configure manually to have the library compiled together).

It was already mentioned first at #31 and lately at #8.

Update Readme

Please update your README. Change npm install ng2-cookies to npm install ng2-cookies --save in order to save this package in package.json.

Does not work the latest Angular CLI build with web pack.

Importing the Cookie class and trying to do a check causes an Error:
import { Cookie } from 'ng2-cookies/ng2-cookies'

Cookie.check('cookName')

Error in web pack build:
Property 'check' does not exist on type 'typeof Cookie'

Set and Gets do not work as well, as there is nothing in the dev console or storage of the newly created (attempted) cookies.

Tried some tests:

  Cookie.check('searchTerm')

  if(!Cookie.get('searchTerm')){
    Cookie.set('searchTerm', term)
  }

  if(!Cookie.get('searchActive')){
    Cookie.set('searchActive', 'true')
  }

None of these tests have work as of yet.

Can't Inject CookieService Mock into Component During Unit Test

When attempting to provide a component with a mock for CookieService, it never gets injected correctly.

Example:

class CookieServiceMock {
    check = jasmine.createSpy('check').and.returnValue(true);
    setMock = jasmine.createSpy('set');
    delete = jasmine.createSpy('delete');
}

describe('assessments-certs.component', function () {
    let fixture: ComponentFixture<AssessmentsAndCertsComponent>;
    let comp: AssessmentsAndCertsComponent;
    let cookieSvcMock: CookieServiceMock;

    beforeEach(async(() => {
        cookieSvcMock = new CookieServiceMock();

        TestBed.configureTestingModule({
            declarations: [
                AssessmentsAndCertsComponent,
                CertificateComponentMock
            ],
            providers: [
                {
                    provide: CookieService,
                    useValue: cookieSvcMock
                }
            ],
            schemas: [CUSTOM_ELEMENTS_SCHEMA]
        }).compileComponents();
    }));

Component (partial code):
@Component({
    selector: 'assessments-certs',
    providers: [CookieService], 
    templateUrl: './assessments-certs.component.html'
})
export class AssessmentsAndCertsComponent {

    constructor(private _cookieSvc: CookieService) {
    }
...
}

Result: _cookieSvc always injects as CookieService(), and not the actual mock. I suspect this is because the CookieService class lacks the @Injectable decorator.

Unable to store boolean value in cookie

If i tried to set cookie value as below

Cookie.setCookie('isAuthenticated', true);

I am getting this error:
error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'.

How to fix this issue?

No need for any configurations to make library work

I added the lib to a fresh Angular project generated using angular-cli. There was no need to change any configuration files as mentioned in README.MD file.

Issuing this command in the project root is enough to add the library:
npm install ng2-cookies --save

Uncaught Syntax: Unexpected token <

Hello. I'm getting the following error when I use your project in the standard angular 2 quick start demo. I'm using the dependency in npm. My package.json file has "ng2-cookies": "^0.1.4" referenced.

Uncaught SyntaxError: Unexpected token <

I've tried importing the module in the index.html

<script src="node_modules/ng2-cookies/ng2-cookies.js"></script>

In the actual service component. I'm importing it as suggested in your readme.

import {Injectable} from 'angular2/core';
import {Cookie} from 'ng2-cookies/ng2-cookies';

@Injectable()
export class AuthenticationService {
  logoutUser() {
     let csrfcookie = Cookie.getCookie('csrftoken');
  }
}

I can't seem to fix the issue. Any help would be appreciated. Thank you!

Project stopped building with versions 1.0.10, 1.0.9

Stack trace:

Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler (position 49:22 in the original .ts file), resolving symbol Cookie in node_modules/ng2-cookies/cookie.d.ts

at positionalError (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:25730:39)
    at simplifyInContext (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:25567:31)
    at StaticReflector.simplify (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:25581:17)
    at StaticReflector.annotations (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:25077:64)
    at NgModuleResolver.resolve (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:17557:86)
    at CompileMetadataResolver.getNgModuleMetadata (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:18058:64)
    at addNgModule (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:24839:62)
    at ./node_modules/@angular/compiler/bundles/compiler.umd.js:24850:18
    at Array.forEach (native)
    at _createNgModules (/opt/atlassian/pipelines/agent/build/node_modules/@angular/compiler/bundles/compiler.umd.js:24849:30)
Compilation failed

Seems like the breaking change was introduced after [email protected]

Option to disable URL encoding in cookie

Please give me a suggestion how to stop url encoding in cooking when i used to store as key value pair.

for ex; i am setting key as 'somepath' and value as '/path/path2/path3' after when i am looking inside browser it is different from actual value it is like %2Fpath%2F% something like this.

Please help me to resolve this.

Delete cookie with empty value

Is there a specific reason your class won't delete a cookie if it has no value? I have a use case to delete a cookie that has no value.

Cheers,
Rob C

Get all attributes of object Cookie

It is possible to get value expiresor createfrom a cookie with this library?

  • If yes. How should this be done?
  • If not. Is possible add this functionality the this library?

This information of print for example:

cookie

I noticed is only possible with the library to get the value of the Contentattribute of the print.

Cannot resolve 'file' or 'directoty'

I'm working from this seed https://github.com/AngularClass/angular2-webpack-starter, and I keep getting these warnings. Is there something I'm missing?

I notice the npm install brings .d.ts files and does not include the .ts files. I'm new to webpack, so I'm not sure If I'm missing something.

It works perfectly if I install from github.

WARNING in ./~/ng2-cookies/ng2-cookies.js
Cannot find source file 'ng2-cookies.ts': Error: Cannot resolve 'file' or 'directory' ./ng2-cookies.ts in /home/dev/code/app/node_modules/ng2-cookies

WARNING in ./~/ng2-cookies/src/services.js
Cannot find source file 'services.ts': Error: Cannot resolve 'file' or 'directory' ./services.ts in /home/dev/code/app/node_modules/ng2-cookies/src

WARNING in ./~/ng2-cookies/src/services/cookie.js
Cannot find source file 'cookie.ts': Error: Cannot resolve 'file' or 'directory' ./cookie.ts in /home/dev/code/app/node_modules/ng2-cookies/src/services

[Improvement] Remove Cookie from methods

Hey,
currently all Methods contain the word Cookie in it.
Example: .deleteCookie, .setCookie, ...

I think it would be better when you only call .delete, .set, .get
Reason: When you use Cookie.setCookie, the second Cookie is not really necessary and I would be shorter.

Add a license file

I really liked your project and I was trying to use it through a WebJar inside a Scala application. The page automatically create a jar ready to be used based on the npm package.

The problem with ng2-cookies is that when the WebJar is being deployed, it requires the package to have a supported license (MIT is supported) and it is not finding any license file on GitHub or inside the package.json.

captura de pantalla de 2017-01-13 13-56-32

size of single cookie is around 1.5KB only.

image

I'm trying to store 3 encoded strings of different size. Ideally cookie it should store cookies of size upto 4KB but it is not going above 1.5KB and I'm not seeing any error either.

app.component.ts:109 => size of string
app.component.ts:112 => this.cookieService.getAll() is logged.

Use a Date object on Cookie.set()

Hey guys. This is only a suggestion.

I needed to use Cookies in my app so I looked for something on npm. At first a came to this repo, but in my app I need to set the Cookie expiration to a precise date and time (even seconds). And then I realized this package only allows for setting the expiration using a delta set in days. And this prevented me from using this repo.

Currently I have implemented what I needed using angular2-cookie. But I just wanted to leave the suggestion for you guys that you allow for setting the expiration date using a Date object, with seconds precision.

Cookie.deleteAll() not working

Hi,

I'm having a issue with Cookie.deleteAll();. It's not cleaning my cookie. Anyont with the same issue?

My component:

import { Cookie } from 'ng2-cookies/ng2-cookies';

...

@Injectable()
export class CookieService {
  ...
    signOut():boolean {
        Cookie.deleteAll();
        return true;
    }
}

Trying to use Cookie as token storage : problem with the refresh.

I'm wondering if you have a solution for my problem.

I'm using the library defining 2 cookies : one called access token and the other called refresh token.

I store inside the cookies tokens retrieved in a json after an http.post on an auth server.

I'm trying to implement the refreshing of the token but the async behave of the http calls is giving me some problem.

Here's the code:
getRefresh Function

  getRefresh(token){

    let params = new URLSearchParams();
    params.append('grant_type','refresh_token');
    params.append('refresh_token',token);
    params.append('client_id','web_app');

    let headers = new Headers({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8','Authorization': 'Basic '+btoa("web_app:")});
    let options = new RequestOptions({headers: headers});

    return this._http.post('http://localhost:9997/oauth/token',params.toString(),options)
      .map(res => res.json())
      .subscribe(
      data => {
        this.saveToken(data)
      });

  }

saveToken Function

  saveToken(token){
   
    var expireDate = 0.00034722222;
    //var expireDate = token.expires_in;

    Cookie.set("access_token", token.access_token, expireDate);
    Cookie.set("refresh_token", token.refresh_token, 1);

    this._router.navigate(['/']);
  }

getResource Function

getResource(resourceUrl): Observable<any> {
    var cookie;

    cookie = Cookie.get("access_token");
    var headers = new Headers({
      'Content-type': 'application/x-www-form-urlencoded; charset=utf-8',
      'Authorization': 'Bearer ' + cookie                            
    });
  
    var options = new RequestOptions({headers: headers});

    return this._http.get(resourceUrl, options)
      .map((res: Response) => res.text())
      .catch((error: any) => Observable.throw(error().json().error || 'Server error'));

  }

Everything starts from the main component that call the service via event bound to a button.

How can i resolve?

Cookie names are encoded

Cookie names are encoded using encodeURIComponent making it impossible to set a valid cookie name with certain characters, specifically #. This is important when writing code to set cookie names matching unchangeable legacy systems and established system standards.

Cookie.deleteAll() not working properly in IE browser.

I am using ng2-Cookie for storing token value and using this cookie in different angular components by importing it. When clicking on logout button (logout method placed in navbar component) from anywhere (different states like home, account, managers components) in the application it's redirecting to the login page(login component) in Chrome and Firefox (working fine) browsers. But it's not working properly in IE browser.
In IE, if logout event fired from home page (homecomponent.ts file, starting of the application after immediate login) then only application is logging out.
And when clearing the cookies of the browser application is redirecting to the login page in Firefox and Chrome browsers but not working as expected in IE browser.
Below is the code I am using

navbar.component.ts
Logout() {
Cookie.deleteAll();
this._router.navigate(['/login']);
}

login.component.ts
ngOnInit() {
let token = Cookie.get('auth_token');
if (token != null && token != undefined && !this._roleauth.isTokenExpired(token)) {
this._router.navigate(['/home']);
}
}

Is it the behavior of ng2-cookie in IE browser? or am I doing in wrong way? Can anyone please help me with this.

Cookie not null

When i set cookie with
Cookie.delete('cookname'); or Cookie.set('cookname', null);

cookie become to string 'null' not null value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.