diff options
Diffstat (limited to 'client/src/app/core/auth/auth.service.ts')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 79239a17a..2ac88c185 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -5,7 +5,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' | |||
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { Router } from '@angular/router' | 6 | import { Router } from '@angular/router' |
7 | import { Notifier } from '@app/core/notification/notifier.service' | 7 | import { Notifier } from '@app/core/notification/notifier.service' |
8 | import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index' | 8 | import { objectToUrlEncoded, peertubeLocalStorage, UserTokens } from '@root-helpers/index' |
9 | import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' | 9 | import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' |
10 | import { environment } from '../../../environments/environment' | 10 | import { environment } from '../../../environments/environment' |
11 | import { RestExtractor } from '../rest/rest-extractor.service' | 11 | import { RestExtractor } from '../rest/rest-extractor.service' |
@@ -34,6 +34,7 @@ export class AuthService { | |||
34 | 34 | ||
35 | loginChangedSource: Observable<AuthStatus> | 35 | loginChangedSource: Observable<AuthStatus> |
36 | userInformationLoaded = new ReplaySubject<boolean>(1) | 36 | userInformationLoaded = new ReplaySubject<boolean>(1) |
37 | tokensRefreshed = new ReplaySubject<void>(1) | ||
37 | hotkeys: Hotkey[] | 38 | hotkeys: Hotkey[] |
38 | 39 | ||
39 | private clientId: string = peertubeLocalStorage.getItem(AuthService.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) | 40 | private clientId: string = peertubeLocalStorage.getItem(AuthService.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) |
@@ -52,9 +53,6 @@ export class AuthService { | |||
52 | this.loginChanged = new Subject<AuthStatus>() | 53 | this.loginChanged = new Subject<AuthStatus>() |
53 | this.loginChangedSource = this.loginChanged.asObservable() | 54 | this.loginChangedSource = this.loginChanged.asObservable() |
54 | 55 | ||
55 | // Return null if there is nothing to load | ||
56 | this.user = AuthUser.load() | ||
57 | |||
58 | // Set HotKeys | 56 | // Set HotKeys |
59 | this.hotkeys = [ | 57 | this.hotkeys = [ |
60 | new Hotkey('m s', (event: KeyboardEvent): boolean => { | 58 | new Hotkey('m s', (event: KeyboardEvent): boolean => { |
@@ -76,6 +74,10 @@ export class AuthService { | |||
76 | ] | 74 | ] |
77 | } | 75 | } |
78 | 76 | ||
77 | buildAuthUser (userInfo: Partial<User>, tokens: UserTokens) { | ||
78 | this.user = new AuthUser(userInfo, tokens) | ||
79 | } | ||
80 | |||
79 | loadClientCredentials () { | 81 | loadClientCredentials () { |
80 | // Fetch the client_id/client_secret | 82 | // Fetch the client_id/client_secret |
81 | this.http.get<OAuthClientLocal>(AuthService.BASE_CLIENT_URL) | 83 | this.http.get<OAuthClientLocal>(AuthService.BASE_CLIENT_URL) |
@@ -180,8 +182,6 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular | |||
180 | 182 | ||
181 | this.user = null | 183 | this.user = null |
182 | 184 | ||
183 | AuthUser.flush() | ||
184 | |||
185 | this.setStatus(AuthStatus.LoggedOut) | 185 | this.setStatus(AuthStatus.LoggedOut) |
186 | 186 | ||
187 | this.hotkeysService.remove(this.hotkeys) | 187 | this.hotkeysService.remove(this.hotkeys) |
@@ -239,7 +239,6 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular | |||
239 | .subscribe({ | 239 | .subscribe({ |
240 | next: res => { | 240 | next: res => { |
241 | this.user.patch(res) | 241 | this.user.patch(res) |
242 | this.user.save() | ||
243 | 242 | ||
244 | this.userInformationLoaded.next(true) | 243 | this.userInformationLoaded.next(true) |
245 | } | 244 | } |
@@ -262,7 +261,6 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular | |||
262 | } | 261 | } |
263 | 262 | ||
264 | this.user = new AuthUser(obj, hashTokens) | 263 | this.user = new AuthUser(obj, hashTokens) |
265 | this.user.save() | ||
266 | 264 | ||
267 | this.setStatus(AuthStatus.LoggedIn) | 265 | this.setStatus(AuthStatus.LoggedIn) |
268 | this.userInformationLoaded.next(true) | 266 | this.userInformationLoaded.next(true) |
@@ -272,7 +270,7 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular | |||
272 | 270 | ||
273 | private handleRefreshToken (obj: UserRefreshToken) { | 271 | private handleRefreshToken (obj: UserRefreshToken) { |
274 | this.user.refreshTokens(obj.access_token, obj.refresh_token) | 272 | this.user.refreshTokens(obj.access_token, obj.refresh_token) |
275 | this.user.save() | 273 | this.tokensRefreshed.next() |
276 | } | 274 | } |
277 | 275 | ||
278 | private setStatus (status: AuthStatus) { | 276 | private setStatus (status: AuthStatus) { |