Enhance OAuth callback to support multiple providers and improve UI/UX styling

This commit is contained in:
2026-01-29 20:29:36 +00:00
parent a00859030e
commit a2163d2f1b

View File

@@ -5,25 +5,25 @@
<div v-if="loading" class="loading-state">
<div class="spinner"></div>
<h2>Authenticating...</h2>
<p>Please wait while we complete your OAuth login</p>
<p>Please wait while we complete your {{ provider }} OAuth login</p>
</div>
<div v-else-if="error" class="error-state">
<div class="error-icon"></div>
<h2>Authentication Failed</h2>
<p class="error-message">{{ error }}</p>
<router-link to="/challonge-test" class="btn btn-primary">
Back to Challonge Test
<router-link to="/auth" class="btn btn-primary">
Back to Authentication Settings
</router-link>
</div>
<div v-else-if="success" class="success-state">
<div class="success-icon"></div>
<h2>Authentication Successful!</h2>
<p>You're now logged in with OAuth</p>
<h2>{{ provider }} Authentication Successful!</h2>
<p>You're now authenticated with {{ provider }}</p>
<p class="redirect-info">Redirecting in {{ countdown }} seconds...</p>
<router-link to="/challonge-test" class="btn btn-primary">
Continue to Challonge Test
<router-link :to="returnTo || '/auth'" class="btn btn-primary">
Continue to Authentication Settings
</router-link>
</div>
</div>
@@ -34,28 +34,36 @@
<script setup>
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useChallongeOAuth } from '../composables/useChallongeOAuth.js';
import { useOAuth } from '../composables/useOAuth.js';
const route = useRoute();
const router = useRouter();
const { exchangeCode } = useChallongeOAuth();
const loading = ref(true);
const error = ref(null);
const success = ref(false);
const countdown = ref(3);
const provider = ref('challonge');
const returnTo = ref(null);
onMounted(async () => {
// Get authorization code and state from URL
// Get provider from query or sessionStorage (default: 'challonge' for backwards compatibility)
provider.value = route.query.provider || sessionStorage.getItem('oauth_provider') || 'challonge';
// Get redirect destination (default: /auth)
returnTo.value = route.query.return_to || sessionStorage.getItem('oauth_return_to') || '/auth';
// Get OAuth parameters from URL
const code = route.query.code;
const state = route.query.state;
const errorParam = route.query.error;
const errorDescription = route.query.error_description;
// Handle OAuth errors
// Handle OAuth errors from provider
if (errorParam) {
loading.value = false;
error.value = errorDescription || `OAuth error: ${errorParam}`;
console.warn(`OAuth error from ${provider.value}:`, errorParam);
return;
}
@@ -67,8 +75,9 @@ onMounted(async () => {
}
try {
// Exchange authorization code for tokens
await exchangeCode(code, state);
// Exchange code for tokens using unified OAuth handler
const oauth = useOAuth(provider.value);
await oauth.exchangeCode(code, state);
loading.value = false;
success.value = true;
@@ -78,7 +87,7 @@ onMounted(async () => {
countdown.value--;
if (countdown.value <= 0) {
clearInterval(interval);
router.push('/challonge-test');
router.push(returnTo.value);
}
}, 1000);
} catch (err) {
@@ -100,148 +109,97 @@ onMounted(async () => {
}
.container {
max-width: 500px;
max-width: 400px;
width: 100%;
}
.callback-card {
background: white;
border-radius: 12px;
padding: 3rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
border-radius: 8px;
padding: 2rem;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}
.loading-state,
.error-state,
.success-state {
text-align: center;
}
/* Loading State */
.loading-state {
padding: 2rem 0;
}
.spinner {
width: 64px;
height: 64px;
border: 5px solid #f3f3f3;
border-top: 5px solid #667eea;
width: 48px;
height: 48px;
border: 4px solid #667eea;
border-top-color: transparent;
border-radius: 50%;
margin: 0 auto 2rem;
animation: spin 1s linear infinite;
animation: spin 0.8s linear infinite;
margin: 0 auto 1rem;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
to {
transform: rotate(360deg);
}
}
/* Success State */
.success-state {
padding: 2rem 0;
.error-icon {
font-size: 3rem;
color: #dc3545;
margin-bottom: 1rem;
}
.success-icon {
width: 80px;
height: 80px;
background: #10b981;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 1.5rem;
font-size: 3rem;
color: white;
animation: scaleIn 0.5s ease;
}
/* Error State */
.error-state {
padding: 2rem 0;
}
.error-icon {
width: 80px;
height: 80px;
background: #ef4444;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 1.5rem;
font-size: 3rem;
color: white;
animation: scaleIn 0.5s ease;
}
@keyframes scaleIn {
0% {
transform: scale(0);
opacity: 0;
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
opacity: 1;
}
color: #28a745;
margin-bottom: 1rem;
}
h2 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 1rem;
color: #1f2937;
margin: 1rem 0;
font-size: 1.5rem;
color: #333;
}
p {
font-size: 1.1rem;
color: #6b7280;
margin-bottom: 1rem;
color: #666;
margin: 0.5rem 0;
}
.error-message {
color: #ef4444;
font-weight: 500;
background: #fff3cd;
border: 1px solid #ffc107;
border-radius: 4px;
padding: 1rem;
background: #fee2e2;
border-radius: 8px;
margin: 1.5rem 0;
margin: 1rem 0;
color: #856404;
}
.redirect-info {
font-size: 0.95rem;
color: #9ca3af;
margin-top: 1rem;
font-size: 0.9rem;
font-weight: 500;
color: #666;
}
.btn {
display: inline-block;
padding: 0.75rem 2rem;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 8px;
font-weight: 600;
margin-top: 1.5rem;
transition: all 0.3s ease;
padding: 0.75rem 1.5rem;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
transition: all 0.2s;
border: none;
cursor: pointer;
font-size: 1rem;
}
.btn:hover {
background: #5568d3;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn-primary {
background: #667eea;
color: white;
}
.btn-primary:hover {
background: #5568d3;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
</style>