Skip to content

Commit 6f33270

Browse files
committed
fix: refreshToken flow
1 parent a3e0681 commit 6f33270

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/extension.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ export function activate(context: vscode.ExtensionContext) {
4343

4444
httpHandler.interceptors.request.use(
4545
async (config) => {
46-
config.headers = {
46+
config.headers = config.baseURL!=="https://securetoken.googleapis.com/v1" ? {
4747
// eslint-disable-next-line @typescript-eslint/naming-convention
4848
'Authorization': `Bearer ${storageManager.get('token', null)}`,
4949
// eslint-disable-next-line @typescript-eslint/naming-convention
5050
'Content-Type': 'application/json'
51+
}:{
52+
// eslint-disable-next-line @typescript-eslint/naming-convention
53+
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
54+
5155
};
5256
return config;
5357
},
@@ -59,8 +63,7 @@ export function activate(context: vscode.ExtensionContext) {
5963
return response;
6064
}, async function (error) {
6165
const originalRequest = error.config;
62-
if (error?.response?.status === 401 && !originalRequest._retry) {
63-
originalRequest._retry = true;
66+
if (error?.response?.status === 401 && originalRequest.baseURL!=="https://securetoken.googleapis.com/v1") {
6467
const token = await refreshAuthToken();
6568
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
6669
return httpHandler(originalRequest);
@@ -75,16 +78,14 @@ export function activate(context: vscode.ExtensionContext) {
7578
baseURL:'https://securetoken.googleapis.com/v1',
7679
url: 'token',
7780
params: {key: FIREBASE_API_KEY},
78-
// eslint-disable-next-line @typescript-eslint/naming-convention
79-
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
8081
data: {
8182
// eslint-disable-next-line @typescript-eslint/naming-convention
8283
grant_type: 'refresh_token',
8384
// eslint-disable-next-line @typescript-eslint/naming-convention
84-
refresh_token: storageManager.get('token')
85+
refresh_token: storageManager.get('refreshToken')
8586
}
8687
};
87-
88+
try{
8889
const response = await httpHandler.request(options);
8990
if(response.status === 200) {
9091
const token = response.data.id_token;
@@ -94,6 +95,10 @@ export function activate(context: vscode.ExtensionContext) {
9495
vscode.window.showErrorMessage("Authentication Failure");
9596
handleLogout();
9697
}
98+
}catch(err){
99+
vscode.window.showErrorMessage("Authentication Failure");
100+
handleLogout();
101+
}
97102
};
98103

99104
function handleLogin(token: string, refreshToken: string) {

0 commit comments

Comments
 (0)