aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers/users/user-tokens.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-12 16:09:02 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-10-24 14:48:24 +0200
commit3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (patch)
treee7f1d12ef5dae1e1142c3a8d0b681c1dbbb0de10 /client/src/root-helpers/users/user-tokens.ts
parent38a3ccc7f8ad0ea94362b58c732af7c387ab46be (diff)
downloadPeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.gz
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.zst
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.zip
Put private videos under a specific subdirectory
Diffstat (limited to 'client/src/root-helpers/users/user-tokens.ts')
-rw-r--r--client/src/root-helpers/users/user-tokens.ts46
1 files changed, 0 insertions, 46 deletions
diff --git a/client/src/root-helpers/users/user-tokens.ts b/client/src/root-helpers/users/user-tokens.ts
deleted file mode 100644
index a6d614cb7..000000000
--- a/client/src/root-helpers/users/user-tokens.ts
+++ /dev/null
@@ -1,46 +0,0 @@
1import { UserTokenLocalStorageKeys } from './user-local-storage-keys'
2
3export class UserTokens {
4 accessToken: string
5 refreshToken: string
6 tokenType: string
7
8 constructor (hash?: Partial<UserTokens>) {
9 if (hash) {
10 this.accessToken = hash.accessToken
11 this.refreshToken = hash.refreshToken
12
13 if (hash.tokenType === 'bearer') {
14 this.tokenType = 'Bearer'
15 } else {
16 this.tokenType = hash.tokenType
17 }
18 }
19 }
20
21 static getUserTokens (localStorage: Pick<Storage, 'getItem'>) {
22 const accessTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.ACCESS_TOKEN)
23 const refreshTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.REFRESH_TOKEN)
24 const tokenTypeLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.TOKEN_TYPE)
25
26 if (!accessTokenLocalStorage || !refreshTokenLocalStorage || !tokenTypeLocalStorage) return null
27
28 return new UserTokens({
29 accessToken: accessTokenLocalStorage,
30 refreshToken: refreshTokenLocalStorage,
31 tokenType: tokenTypeLocalStorage
32 })
33 }
34
35 static saveToLocalStorage (localStorage: Pick<Storage, 'setItem'>, tokens: UserTokens) {
36 localStorage.setItem(UserTokenLocalStorageKeys.ACCESS_TOKEN, tokens.accessToken)
37 localStorage.setItem(UserTokenLocalStorageKeys.REFRESH_TOKEN, tokens.refreshToken)
38 localStorage.setItem(UserTokenLocalStorageKeys.TOKEN_TYPE, tokens.tokenType)
39 }
40
41 static flushLocalStorage (localStorage: Pick<Storage, 'removeItem'>) {
42 localStorage.removeItem(UserTokenLocalStorageKeys.ACCESS_TOKEN)
43 localStorage.removeItem(UserTokenLocalStorageKeys.REFRESH_TOKEN)
44 localStorage.removeItem(UserTokenLocalStorageKeys.TOKEN_TYPE)
45 }
46}