mirror of
https://github.com/open-webui/open-webui
synced 2025-05-12 09:31:34 +00:00
fix: Improve Google OAuth token retrieval with proper Promise handling
This commit is contained in:
parent
c3d631ca98
commit
ba19ff8ace
@ -59,16 +59,24 @@ export const loadGoogleAuthApi = () => {
|
|||||||
|
|
||||||
export const getAuthToken = async () => {
|
export const getAuthToken = async () => {
|
||||||
if (!oauthToken) {
|
if (!oauthToken) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const tokenClient = google.accounts.oauth2.initTokenClient({
|
const tokenClient = google.accounts.oauth2.initTokenClient({
|
||||||
client_id: CLIENT_ID,
|
client_id: CLIENT_ID,
|
||||||
scope: SCOPE.join(' '),
|
scope: SCOPE.join(' '),
|
||||||
callback: (response: any) => {
|
callback: (response: any) => {
|
||||||
if (response.access_token) {
|
if (response.access_token) {
|
||||||
oauthToken = response.access_token;
|
oauthToken = response.access_token;
|
||||||
|
resolve(oauthToken);
|
||||||
|
} else {
|
||||||
|
reject(new Error('Failed to get access token'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
error_callback: (error: any) => {
|
||||||
|
reject(new Error(error.message || 'OAuth error occurred'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tokenClient.requestAccessToken();
|
||||||
});
|
});
|
||||||
await tokenClient.requestAccessToken();
|
|
||||||
}
|
}
|
||||||
return oauthToken;
|
return oauthToken;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user