-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: set jwt token to a cookie instead of localStorage
- Loading branch information
1 parent
2127c1d
commit 48425c8
Showing
15 changed files
with
370 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export * from './services/token-interceptor.service'; | ||
export * from './services/local-storage-jwt.service'; | ||
export * from './services/auth-guard'; | ||
|
||
export { AuthStore } from './auth.store'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { inject } from '@angular/core'; | ||
import { map, Observable, take } from 'rxjs'; | ||
import { Router, UrlTree } from '@angular/router'; | ||
import { AuthStore } from '../auth.store'; | ||
|
||
import { LocalStorageJwtService } from './local-storage-jwt.service'; | ||
|
||
export const authGuard = (): Observable<boolean | UrlTree> => { | ||
const storage = inject(LocalStorageJwtService); | ||
export const authGuard = (): boolean | UrlTree => { | ||
const router = inject(Router); | ||
const authStore = inject(AuthStore); | ||
|
||
if (!authStore.loggedIn()) { | ||
return router.parseUrl('/login'); | ||
} | ||
|
||
return storage.getItem().pipe( | ||
map((token) => { | ||
if (!token) { | ||
return router.parseUrl('/login'); | ||
} | ||
return true; | ||
}), | ||
take(1), | ||
); | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
libs/auth/data-access/src/services/local-storage-jwt.service.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
libs/auth/data-access/src/services/token-interceptor.service.spec.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
libs/auth/data-access/src/services/token-interceptor.service.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.