diff options
Diffstat (limited to 'client/src/standalone')
-rw-r--r-- | client/src/standalone/videos/embed.ts | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 1dca84f72..adba32a31 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -79,9 +79,6 @@ export class PeerTubeEmbed { | |||
79 | .then((res: Response) => { | 79 | .then((res: Response) => { |
80 | if (res.status !== 401) return res | 80 | if (res.status !== 401) return res |
81 | 81 | ||
82 | // 401 unauthorized is not catch-ed, but then-ed | ||
83 | const error = res | ||
84 | |||
85 | const refreshingTokenPromise = new Promise((resolve, reject) => { | 82 | const refreshingTokenPromise = new Promise((resolve, reject) => { |
86 | const clientId: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) | 83 | const clientId: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID) |
87 | const clientSecret: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_SECRET) | 84 | const clientSecret: string = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_SECRET) |
@@ -101,24 +98,37 @@ export class PeerTubeEmbed { | |||
101 | headers, | 98 | headers, |
102 | method: 'POST', | 99 | method: 'POST', |
103 | body: objectToUrlEncoded(data) | 100 | body: objectToUrlEncoded(data) |
104 | }).then(res => res.json()) | 101 | }).then(res => { |
105 | .then((obj: UserRefreshToken) => { | 102 | if (res.status === 401) return undefined |
106 | this.userTokens.accessToken = obj.access_token | ||
107 | this.userTokens.refreshToken = obj.refresh_token | ||
108 | this.userTokens.save() | ||
109 | 103 | ||
110 | this.setHeadersFromTokens() | 104 | return res.json() |
105 | }).then((obj: UserRefreshToken & { code: 'invalid_grant'}) => { | ||
106 | if (!obj || obj.code === 'invalid_grant') { | ||
107 | Tokens.flush() | ||
108 | this.removeTokensFromHeaders() | ||
111 | 109 | ||
112 | resolve() | 110 | return resolve() |
113 | }) | 111 | } |
112 | |||
113 | this.userTokens.accessToken = obj.access_token | ||
114 | this.userTokens.refreshToken = obj.refresh_token | ||
115 | this.userTokens.save() | ||
116 | |||
117 | this.setHeadersFromTokens() | ||
118 | |||
119 | resolve() | ||
120 | }) | ||
114 | .catch((refreshTokenError: any) => { | 121 | .catch((refreshTokenError: any) => { |
115 | reject(refreshTokenError) | 122 | reject(refreshTokenError) |
116 | }) | 123 | }) |
117 | }) | 124 | }) |
118 | 125 | ||
119 | return refreshingTokenPromise | 126 | return refreshingTokenPromise |
120 | .catch(() => this.removeTokensFromHeaders()) | 127 | .catch(() => { |
121 | .then(() => fetch(url, { | 128 | Tokens.flush() |
129 | |||
130 | this.removeTokensFromHeaders() | ||
131 | }).then(() => fetch(url, { | ||
122 | ...options, | 132 | ...options, |
123 | headers: this.headers | 133 | headers: this.headers |
124 | })) | 134 | })) |