hello.js icon indicating copy to clipboard operation
hello.js copied to clipboard

Support on auth.error event

Open MrSwitch opened this issue 7 years ago • 14 comments

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.

MrSwitch avatar Feb 17 '18 17:02 MrSwitch

Can you assign this issue to me

raj-adi00 avatar Oct 14 '24 19:10 raj-adi00

Can you tell me how can i check the issue?

raj-adi00 avatar Oct 16 '24 20:10 raj-adi00

// 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}); });

rajj28 avatar Jan 17 '25 18:01 rajj28

Hi does this issue still need to be fixed? I'll be happy to work on it

MrRob0t404 avatar Feb 26 '25 03:02 MrRob0t404

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

helennavwezzy avatar Mar 22 '25 07:03 helennavwezzy

is this issue resolved i would like to work on with or is this issue reassigned to anyone please let me know

elanchezhiyan2005 avatar Apr 03 '25 03:04 elanchezhiyan2005

i would like to work on it if not resolved does it still needs too be fixed

91FAhmed avatar May 27 '25 07:05 91FAhmed

I Would like to work on this issue if it is not solved yet. Can you assign me.

Mubashir2611 avatar Jun 17 '25 07:06 Mubashir2611

I will work on this issue, but i think you forgot to close it.

Kunal-sharmaa avatar Jul 03 '25 10:07 Kunal-sharmaa

I would like to work on solving this issue if the issue is not solved yet.

Govind-553 avatar Jul 04 '25 09:07 Govind-553

I would like to work on solving this issue if the issue is not solved yet.

nidhi-ux avatar Aug 05 '25 17:08 nidhi-ux

// 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}); });

somesh-coder-dev avatar Aug 11 '25 23:08 somesh-coder-dev

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?

habitat1998 avatar Oct 28 '25 08:10 habitat1998

Can I work on this if still open?

shrutipandya3 avatar Oct 28 '25 09:10 shrutipandya3