admin管理员组文章数量:1291048
I'm here because I'm frustrated and stuck. I have tried different possible solutions but I can't find my mistake... I'm using native server side rendering of angular (not Angular Material). The problem is in the server side requests, these are sent without cookies, so when the user refreshes the app, the first api call is received without user data (it can be tested here: )
I'm using SsrCookieService ([email protected]), but it doesn't seem to work
I have added REQUEST & RESPONSE in server.ts providers:
providers: [
provide: APP_BASE_HREF, useValue: baseUrl },
provide: 'REQUEST', useValue: req },
provide: 'RESPONSE', useValue: res },
]
And this is part of my app.config.ts file:
export const appConfig: ApplicationConfig = {
providers: [
SsrCookieService, ...
]
}
I think the error may be one of the following:
- The cookie is httpOnly and secure, and it can be used by Javascript (I can't believe this, because... How do you identify user from Server side api calls then? No localStorage, no cookies...)
- I need to do something else to configure ngx-cookie-service to work correctly
- I have deployed both environments (backend and frontend) in the same VPS server, but the api calls routes aren't using localhost, I'm pointing /... So it does not work because this?
- I have to configure something else in the nginx file
I have tried everything I found but there is not much information, not even in the official Angular documentation.
I'm here because I'm frustrated and stuck. I have tried different possible solutions but I can't find my mistake... I'm using native server side rendering of angular (not Angular Material). The problem is in the server side requests, these are sent without cookies, so when the user refreshes the app, the first api call is received without user data (it can be tested here: https://diecasttracker/basic-cars)
I'm using SsrCookieService ([email protected]), but it doesn't seem to work
I have added REQUEST & RESPONSE in server.ts providers:
providers: [
provide: APP_BASE_HREF, useValue: baseUrl },
provide: 'REQUEST', useValue: req },
provide: 'RESPONSE', useValue: res },
]
And this is part of my app.config.ts file:
export const appConfig: ApplicationConfig = {
providers: [
SsrCookieService, ...
]
}
I think the error may be one of the following:
- The cookie is httpOnly and secure, and it can be used by Javascript (I can't believe this, because... How do you identify user from Server side api calls then? No localStorage, no cookies...)
- I need to do something else to configure ngx-cookie-service to work correctly
- I have deployed both environments (backend and frontend) in the same VPS server, but the api calls routes aren't using localhost, I'm pointing https://api.diecasttracker/api/... So it does not work because this?
- I have to configure something else in the nginx file
I have tried everything I found but there is not much information, not even in the official Angular documentation.
Share Improve this question asked Feb 13 at 15:04 Ruben GarciaRuben Garcia 11 bronze badge 01 Answer
Reset to default 0can you try cookie-parser package. I've already use this package for angular 17 SSR web application.It's more similar with localstorage.follow below steps for use.
- install package using npm :
npm i cookie-parser
- import CookieService from package.
import { CookieService } from 'ngx-cookie-service';
- initialize it in constructor
constructor(private cookieservice: CookieService){}
- now you can use this service for get and set a data same as localstorage.
// set method to set data
this.cookiservice.set('userName', 'Utsav Sheta');
// get method to get data
this.cookiservice.get('userName')
本文标签: nodejsCookies not sent in server request of Angular SSR (v18)Stack Overflow
版权声明:本文标题:node.js - Cookies not sent in server request of Angular SSR (v18) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741522357a2383264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论