express - Angular2, ExpressJS, PassportJS Not able to maintain sessions -
i using angular2, express , passport application. i've created api in express , i'm able login through postman chrom extension. i'm able login angular2 application well. in postman express maintaining sessions. in angular2 express not maintaining sessions.
below 1 respons in angular2 app:
and response in postman application:
i'm attaching code here well:
this code in angular2 service
private _options = new requestoptions({ headers: new headers({ 'content-type': 'application/json' })}); constructor(private _http: http){ } login(credentials: object){ return this._http.post('http://localhost:1234/api/login', json.stringify(credentials), this._options); }
i've configured express cors requests well. though i'm unable maintain sessions in expressjs.
app.use(bodyparser.json()); //cors in express app.use(function(req, res, next) { res.header('access-control-allow-credentials', true); res.header('access-control-allow-origin', req.headers.origin); res.header('access-control-allow-methods', 'get,put,post,delete'); res.header('access-control-allow-headers', 'x-requested-with, x-http-method-override, content-type, accept'); if ('options' == req.method) { res.sendstatus(200); } else { next(); } });
Comments
Post a Comment