Skip to content

Commit 7857f0a

Browse files
Exponer window.CodericAccountProfile al autenticar (fetch /api/account/profile)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 056e539 commit 7857f0a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

assets/js/auth0-coderic.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,28 @@
2929
escapeHtml(name) +
3030
'</span><button type="button" id="coderic-logout-btn" class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-orange-500">Cerrar sesión</button>';
3131
document.getElementById("coderic-logout-btn").addEventListener("click", function () {
32+
window.CodericAccountProfile = null;
3233
window.CodericAuth0Client.logout({
3334
logoutParams: { returnTo: redirectUri },
3435
});
3536
});
37+
fetchAndSetAccountProfile();
38+
}
39+
40+
/** Obtiene /api/account/profile y lo expone en window.CodericAccountProfile para todo el sitio. */
41+
function fetchAndSetAccountProfile() {
42+
if (!window.CodericAuth0Client) return;
43+
window.CodericAuth0Client.getTokenSilently()
44+
.then(function (token) {
45+
return fetch("/api/account/profile", { headers: { Authorization: "Bearer " + token } });
46+
})
47+
.then(function (r) { return r.ok ? r.json() : null; })
48+
.then(function (data) {
49+
window.CodericAccountProfile = data || null;
50+
})
51+
.catch(function () {
52+
window.CodericAccountProfile = null;
53+
});
3654
}
3755

3856
function escapeHtml(s) {

0 commit comments

Comments
 (0)