Support on auth.error event
On page redirect authentication login is captured. However errors are not.
e.g. stored in localstorage would be...
{
"adB2CSignInSignUp": {
"error": {
"code": "access_denied",
"message": "AADB2C90118:+The+user+has+forgotten+their+password.\r\nCorrelation+ID:+3f341530-ed9a-4546-a646-2e2ac3e3b43d\r\nTimestamp:+2017-07-25+19:29:24Z\r\n"
},
"error_description": "AADB2C90118:+The+user+has+forgotten+their+password.\r\nCorrelation+ID:+3f341530-ed9a-4546-a646-2e2ac3e3b43d\r\nTimestamp:+2017-07-25+19:29:24Z\r\n",
"state": "",
"client_id": "da7caa3a-739c-436c-a32b-b428d3e8c043",
"network": "adB2CSignInSignUp",
"display": "page",
"redirect_uri": "https://localhost:44369/redirect",
"scope": "openid,https://foobar.onmicrosoft.com/foobarapi/use",
"page_uri": "https://localhost:44369"
}
}
This should trigger any listeners on auth.error on page load.
Can you assign this issue to me
Can you tell me how can i check the issue?
// Define a function to trigger auth error listeners function triggerAuthErrorListeners(error) { // Example: Trigger a custom event for error handling const event = new CustomEvent('auth.error', { detail: error }); window.dispatchEvent(event);
// You can also directly call error handlers here
console.error('Auth Error:', error);
}
// On page load, check for auth-related errors in localStorage document.addEventListener('DOMContentLoaded', () => { const authDataKey = 'adB2CSignInSignUp'; // Key where auth data is stored const authDataJson = localStorage.getItem(authDataKey);
if (authDataJson) {
try {
const authData = JSON.parse(authDataJson);
// Check if there's an error field in the stored data
if (authData.error) {
triggerAuthErrorListeners(authData.error);
// Optionally remove the item from localStorage after handling
localStorage.removeItem(authDataKey);
}
} catch (e) {
console.error('Error parsing auth data from localStorage:', e);
}
}
});
// Example listener for 'auth.error'
window.addEventListener('auth.error', (event) => {
const error = event.detail;
alert(Authentication Error: ${error.message});
});
Hi does this issue still need to be fixed? I'll be happy to work on it
Use Case This feature will improve the developer experience by:
- Allowing better handling of authentication errors without manually parsing localStorage.
- Simplifying the error handling logic for Single Page Applications (SPAs).
- Enabling UI feedback (e.g., "You canceled login" or "Session expired") automatically based on the auth.error event
is this issue resolved i would like to work on with or is this issue reassigned to anyone please let me know
i would like to work on it if not resolved does it still needs too be fixed
I Would like to work on this issue if it is not solved yet. Can you assign me.
I will work on this issue, but i think you forgot to close it.
I would like to work on solving this issue if the issue is not solved yet.
I would like to work on solving this issue if the issue is not solved yet.
// Utility to trigger the auth.error event function triggerAuthErrorListeners(error) { const event = new CustomEvent('auth.error', { detail: error }); window.dispatchEvent(event); console.error('Auth Error:', error); }
document.addEventListener('DOMContentLoaded', () => { const authKey = 'adB2CSignInSignUp'; const authDataJson = localStorage.getItem(authKey);
if (authDataJson) {
try {
const authData = JSON.parse(authDataJson);
if (authData.error) {
triggerAuthErrorListeners(authData.error);
localStorage.removeItem(authKey); // prevent repeat firing
}
} catch (e) {
console.error('Error parsing auth data:', e);
}
}
});
// Example usage: listen for the auth.error event
window.addEventListener('auth.error', event => {
const { code, message } = event.detail;
alert(Authentication Error (${code}): ${message});
});
Hello! I’m interested in fixing this issue as my first contribution. Could I take this one if no one else is currently working on it?
Can I work on this if still open?