📝 Reformat code for improved readability and consistency in the OAuth composable

This commit is contained in:
2026-01-29 15:21:20 +00:00
parent 0a5e1b9251
commit 8093cc8d2a

View File

@@ -118,8 +118,12 @@ export function useOAuth(provider = 'challonge') {
* @throws {Error} If OAuth credentials not configured
*/
function getAuthorizationUrl(scopeOrOptions, options = {}) {
const clientId = import.meta.env[`VITE_${provider.toUpperCase()}_CLIENT_ID`];
const redirectUri = import.meta.env[`VITE_${provider.toUpperCase()}_REDIRECT_URI`];
const clientId = import.meta.env[
`VITE_${provider.toUpperCase()}_CLIENT_ID`
];
const redirectUri = import.meta.env[
`VITE_${provider.toUpperCase()}_REDIRECT_URI`
];
if (!clientId || !redirectUri) {
throw new Error(
@@ -182,7 +186,10 @@ export function useOAuth(provider = 'challonge') {
sessionStorage.setItem('oauth_return_to', returnTo);
}
console.log(`🔐 Starting ${provider} OAuth flow with state:`, state.substring(0, 8) + '...');
console.log(
`🔐 Starting ${provider} OAuth flow with state:`,
state.substring(0, 8) + '...'
);
// Redirect to OAuth provider
window.location.href = authUrl;
@@ -214,7 +221,9 @@ export function useOAuth(provider = 'challonge') {
}
if (storedProvider !== provider) {
const err = new Error(`Provider mismatch: expected ${storedProvider}, got ${provider}`);
const err = new Error(
`Provider mismatch: expected ${storedProvider}, got ${provider}`
);
state.error.value = err.message;
throw err;
}
@@ -268,7 +277,9 @@ export function useOAuth(provider = 'challonge') {
sessionStorage.removeItem('oauth_provider');
sessionStorage.removeItem('oauth_return_to');
console.log(`${provider} OAuth authentication successful, expires in ${data.expires_in}s`);
console.log(
`${provider} OAuth authentication successful, expires in ${data.expires_in}s`
);
return tokens;
} catch (err) {
state.error.value = err.message;
@@ -331,7 +342,9 @@ export function useOAuth(provider = 'challonge') {
state.tokens.value = tokens;
localStorage.setItem(state.storageKey, JSON.stringify(tokens));
console.log(`${provider} token refreshed, new expiry in ${data.expires_in}s`);
console.log(
`${provider} token refreshed, new expiry in ${data.expires_in}s`
);
return tokens;
} catch (err) {
state.error.value = err.message;
@@ -363,7 +376,9 @@ export function useOAuth(provider = 'challonge') {
// Refresh if expired or expiring within 5 minutes
if (expiresIn < fiveMinutes) {
console.log(`🔄 ${provider} token expiring in ${Math.floor(expiresIn / 1000)}s, refreshing...`);
console.log(
`🔄 ${provider} token expiring in ${Math.floor(expiresIn / 1000)}s, refreshing...`
);
await refreshTokenFn();
}
@@ -392,7 +407,9 @@ export function useOAuth(provider = 'challonge') {
function generateState() {
const array = new Uint8Array(32);
crypto.getRandomValues(array);
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join(
''
);
}
return {