fullstackproltd / AspNetCoreSpa

Asp.Net 7.0 & Angular 15 SPA Fullstack application with plenty of examples. Live demo:
https://aspnetcorespa.fullstackpro.co.uk
MIT License
1.47k stars 464 forks source link

Cookie or Authorization barrer token in auth-interceptor.ts #211

Closed kmiskiewicz closed 6 years ago

kmiskiewicz commented 6 years ago

Hi Asad,

I hope you are well, I was going trough the code and in the auth-interceptor.ts I found something which I have problem to figure out. Why we have if statement on two not related things: culture and bearer token?

if (isPlatformServer(this.platformId)) { headers = req.headers.set('Cookie', this.getCultureCookie()); } else { headers = req.headers.set('Authorization', 'Bearer ' + auth.accessToken); }

Here is a link to the line: https://github.com/asadsahi/AspNetCoreSpa/blob/64faeca0dab613ddd6307ab3ce0651575a717e02/ClientApp/src/app/core/services/interceptors/auth-interceptor.ts#L21

Best regards, Krzysztof

asadsahi commented 6 years ago

@kmiskiewicz this logic says that only send cookies if environment is server, and only attach Authorization header if it is browser environment.

This code was added in order to prepare project for SSR, but in current master SSR isn't implemented fully because of some issues with it. I have simplified this logic, see this change.

I am planning to make SSR working and alot more improvements in dev branch which will be merged into master after .net 2.1 release and hopefully angular 6 by that time as well. You can still try out dev branch as there are alot of improvements and the same cookie logic which was in authe.interceptor has been moved into a seperate interceptor. Also, worth mentioning, .net build and runtime performance has massively improved. So, keep an eye :)

kmiskiewicz commented 6 years ago

Thank you, I didn't check the new dev version my bad, I'll observe the dev branch as well, really great job!