Check authentication on each page reload
- Ngôn ngữ chính
- TypeScript
- Star
- 25.7k
- Fork
- 7.9k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### Issue type
**I'm submitting a ...** (check one with "x")
* [ ] bug report
* [X] feature request
* [ ] question about the decisions made in the repository
### Issue description
**Current behavior:**
I'm using existing `NbPasswordAuthStrategy` and after the user becomes authenticated, the auth token successfully stores in `localStorage` and persists there until explicitly loggin out. Even if I restart by backend (which is implemented in Spring with Spring security), the user is still authenticated on a frontend but gets 401 doing request to a backend.
**Expected behavior:**
I was expecting that user authority will be checked on each page reload or in some other way (making a call to some `/users/me` endpoint). Please, suggest me what is the proper way to achieve this.
**UPD** I can see someone implements this via http interceptors but maybe such behaviour could be added to a framework 'out-of-the-box'.
**Steps to reproduce:**
- Authenticate user
- Restart backend
- User token still exists in local storage
**Related code:**
I decided to try to implement custom `NbTokenStorage` and override desired methods (one of or all of `set`, `get`, `clear`) and sticked into a `get` method, where I can check if the user is still authenticated on a backend, but this requires to make an http call while method should return a token itself instead of `Observable` and it seems that I've stand on a wrong path.
### Other information:
**npm, node, OS, Browser**
```
node v16.3.0
npm 7.15.1
OS Linux (KDE Neon)
Browser: Chrome
```
**Angular, Nebular**
```
{
***
},
"private": true,
"dependencies": {
"@angular/animations": "~12.0.3",
"@angular/cdk": "^12.0.4",
"@angular/common": "~12.0.3",
"@angular/compiler": "~12.0.3",
"@angular/core": "~12.0.3",
"@angular/forms": "~12.0.3",
"@angular/platform-browser": "~12.0.3",
"@angular/platform-browser-dynamic": "~12.0.3",
"@angular/router": "~12.0.3",
"@nebular/auth": "^7.0.0",
"@nebular/eva-icons": "^7.0.0",
"@nebular/theme": "^7.0.0",
"bootstrap": "^4.6.0",
"eva-icons": "^1.1.3",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.0.3",
"@angular/cli": "~12.0.3",
"@angular/compiler-cli": "~12.0.3",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.7.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.2.3"
}
}
```
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.