-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.html
More file actions
75 lines (61 loc) · 3.05 KB
/
callback.html
File metadata and controls
75 lines (61 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
layout: default
title: Authenticating
permalink: /callback/
---
<div class="min-h-[80vh] w-full flex flex-col items-center justify-center relative overflow-hidden" id="auth-callback-container">
<div class="glass p-10 sm:p-12 rounded-3xl w-full max-w-lg z-10 shadow-2xl flex flex-col items-center border border-surface-border bg-surface-panel/50 backdrop-blur-xl">
<h1 class="text-2xl font-bold text-[var(--text-base)] mb-6 text-center">Verifying Authentication...</h1>
<div id="loading-spinner" class="animate-spin rounded-full h-12 w-12 border-b-2 border-coderic-500"></div>
<p id="callback-message" class="mt-6 text-sm text-muted text-center">Please wait while we establish your secured session with Coderic Identity Cloud.</p>
<div id="error-box" class="hidden mt-6 p-4 bg-red-900/40 border border-red-500/50 rounded-xl text-red-200 text-sm text-center w-full"></div>
<a href="/" id="return-home-btn" class="hidden mt-6 text-coderic-400 hover:text-coderic-300 text-sm underline underline-offset-4">Return Home</a>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const spinner = document.getElementById('loading-spinner');
const msg = document.getElementById('callback-message');
const errBox = document.getElementById('error-box');
const returnBtn = document.getElementById('return-home-btn');
const showError = (message) => {
spinner.classList.add('hidden');
msg.classList.add('hidden');
errBox.classList.remove('hidden');
errBox.innerText = message;
returnBtn.classList.remove('hidden');
};
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
const state = params.get('state');
const error = params.get('error');
if (error) {
return showError('Authentication Failed: ' + (params.get('error_description') || error));
}
if (!code) {
// Normal fallback for direct visit
return window.location.replace('/');
}
try {
if (typeof codericGetAuth0Client !== 'function') {
throw new Error('Auth0 no está inicializado. Verificá que el layout incluya el header y el SDK en head.');
}
const client = await codericGetAuth0Client();
const result = await client.handleRedirectCallback();
// Limpia la URL (remove code/state)
window.history.replaceState({}, document.title, window.location.pathname);
const returnUrl = (result && result.appState && result.appState.returnTo)
? String(result.appState.returnTo)
: '/';
msg.innerText = 'Success! Redirecting...';
msg.classList.remove('text-muted');
msg.classList.add('text-coderic-500', 'font-bold');
setTimeout(() => {
window.location.replace(returnUrl);
}, 300);
} catch (err) {
console.error('Callback error:', err);
showError(err.message || 'An unexpected error occurred during authentication.');
}
});
</script>