Refactor code for improved readability and consistency
- Updated CSRF middleware to enhance cookie value decoding. - Reformatted OAuth proxy token store initialization for better clarity. - Adjusted Challonge proxy router for consistent line breaks and readability. - Enhanced OAuth router error handling and response formatting. - Improved session router for better readability and consistency in fetching provider records. - Refactored OAuth token store to improve key derivation logging. - Cleaned up cookie options utility for better readability. - Enhanced Challonge client credentials composable for consistent API calls. - Streamlined OAuth composable for improved logging. - Refactored main.js for better readability in session initialization. - Improved Challonge v2.1 service error handling for better clarity. - Cleaned up API client utility for improved readability. - Enhanced ApiKeyManager.vue for better text formatting. - Refactored ChallongeTest.vue for improved readability in composable usage.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import express from 'express';
|
||||
import fetch from 'node-fetch';
|
||||
import { COOKIE_NAMES, getCsrfCookieOptions, generateToken } from '../utils/cookie-options.js';
|
||||
import {
|
||||
COOKIE_NAMES,
|
||||
getCsrfCookieOptions,
|
||||
generateToken
|
||||
} from '../utils/cookie-options.js';
|
||||
|
||||
export function createSessionRouter({ config, tokenStore }) {
|
||||
const router = express.Router();
|
||||
@@ -75,7 +79,8 @@ export function createSessionRouter({ config, tokenStore }) {
|
||||
return res.status(500).json({ error: 'SID middleware not configured' });
|
||||
}
|
||||
|
||||
const challonge = (await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
const challonge =
|
||||
(await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
|
||||
return res.json({
|
||||
sid: req.sid,
|
||||
@@ -83,9 +88,13 @@ export function createSessionRouter({ config, tokenStore }) {
|
||||
hasApiKey: !!challonge.api_key?.token,
|
||||
hasUserOAuth: !!challonge.user_oauth?.access_token,
|
||||
userOAuthExpiresAt: challonge.user_oauth?.expires_at || null,
|
||||
hasClientCredentials: !!(challonge.client_credentials?.client_id && challonge.client_credentials?.client_secret),
|
||||
hasClientCredentials: !!(
|
||||
challonge.client_credentials?.client_id &&
|
||||
challonge.client_credentials?.client_secret
|
||||
),
|
||||
hasClientCredentialsToken: !!challonge.client_credentials?.access_token,
|
||||
clientCredentialsExpiresAt: challonge.client_credentials?.expires_at || null
|
||||
clientCredentialsExpiresAt:
|
||||
challonge.client_credentials?.expires_at || null
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -96,17 +105,23 @@ export function createSessionRouter({ config, tokenStore }) {
|
||||
return res.status(500).json({ error: 'SID middleware not configured' });
|
||||
}
|
||||
|
||||
const challonge = (await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
const challonge =
|
||||
(await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
|
||||
const base = 'https://api.challonge.com/v2.1/tournaments.json?page=1&per_page=1&state=pending';
|
||||
const base =
|
||||
'https://api.challonge.com/v2.1/tournaments.json?page=1&per_page=1&state=pending';
|
||||
const results = {
|
||||
sid: req.sid,
|
||||
endpoints: {
|
||||
userTournamentsSample: base,
|
||||
appTournamentsSample: 'https://api.challonge.com/v2.1/application/tournaments.json?page=1&per_page=1&state=pending'
|
||||
appTournamentsSample:
|
||||
'https://api.challonge.com/v2.1/application/tournaments.json?page=1&per_page=1&state=pending'
|
||||
},
|
||||
methods: {
|
||||
user_oauth: { present: !!challonge.user_oauth?.access_token, probe: null },
|
||||
user_oauth: {
|
||||
present: !!challonge.user_oauth?.access_token,
|
||||
probe: null
|
||||
},
|
||||
api_key: { present: !!challonge.api_key?.token, probe: null },
|
||||
client_credentials: {
|
||||
present: !!challonge.client_credentials?.access_token,
|
||||
|
||||
Reference in New Issue
Block a user