# How to handle access denied response

**URL:** <https://community.auth0.com/t/how-to-handle-access-denied-response/136668>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [June 19, 2024, 7:12pm UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668 "2024-06-19T19:12:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabor.ottlik.hun](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gabor.ottlik.hun/32/57175_2.png) [@gabor.ottlik.hun](https://community.auth0.com/u/gabor.ottlik.hun)\
**Post date:** [June 19, 2024, 7:12pm UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/1 "2024-06-19T19:12:35Z")

</div>

Hi folks,

I enabled Actions/Flow post login action - white list user. I set the secret and tryed to log in with a user which is not in the white list users.

Unfortunately when I call api/auth/login by clicking on the login button I get redirected to the following url:  
`http://localhost:3000/api/auth/callback?error=access_denied&error_description=access%20denied.&state=eyJyZXR1cm5UbyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJ9`

I use the action from the template. And not sure how to handle this. I’m expected to get redirected to the Universal Login page and able to try to login with another user which is in the whitelist but I keep redirected to the aforementioned url.

Tried many thing to handle:

```auto
const afterCallback: AfterCallbackAppRoute = (
	reqest: NextRequest,
	session: Session,
	state: { [key: string]: any } | undefined,
): Promise<Session | Response | undefined> | Session | Response | undefined => {
	// if (session.user) {
	// return session;
	// } else {
	// redirect('/');
	// }

	if (state) state.returnTo = '/';
	return session;
};

export const GET = handleAuth({
	callback: handleCallback({
		afterCallback,
		redirectUri: 'http://localhost:3000',
		authorizationParams: {
			redirect_uri: 'http://localhost:3000'
		}
	}),
	login: handleLogin({
		returnTo: 'http://localhost:3000',
		authorizationParams: {
			prompt: 'consent'
		}
	}),
});

```

Nothing worked.  
Some guidance would be deeply appreciated.

Kind regards,  
Gabor

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 28, 2024, 9:59pm UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/3 "2024-06-28T21:59:50Z")

</div>

Hi @gabor.ottlik.hun,

When you use the `api.access.deny()` method, it will deny users from logging in, but their session will remain intact. So, in subsequent login attempts, the user will continuously be sent to the error page (`http://localhost:3000/api/auth/callback?error=access_denied&error_description=access%20denied.&state=eyJyZXR1cm5UbyI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJ9`) until the user logs out.

That said, you will need to log the user out whenever they have been denied access to kill the session. This way, they can try logging in again with another user. To do so, please redirect your users to the `/v2/logout` endpoint.

See [this knowledge solution](https://community.auth0.com/t/cannot-get-back-to-login-screen-after-getting-denied-by-post-login-action/115808) as a reference.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![gabor.ottlik.hun](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gabor.ottlik.hun/32/57175_2.png) [@gabor.ottlik.hun](https://community.auth0.com/u/gabor.ottlik.hun)\
**Post date:** [June 29, 2024, 10:22am UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/5 "2024-06-29T10:22:28Z")

</div>

Thanks, this solved my first use case.

```auto
auth0.handleAuth({
		callback: auth0.handleCallback({
			redirectUri: `http://${subdomain}.localhost:3001/api/auth/logout`,
		}),
		'update-session': auth0.handleProfile({ refetch: true }),
		'silent-login': auth0.handleLogin({
			authorizationParams: {
				prompt: 'none',
				redirect_uri: `http://${subdomain}.localhost:3001/api/auth/login`,
			},
		}),
		logout: auth0.handleLogout({
			returnTo: `http://${subdomain}.localhost:3001`,
		}),
	})

```

Keep in mind that I redirect from / root to silent-login:

```auto
if (!user && !userId && !isLoading) {
	router.push('/api/auth/silent-login');
}

```

But there is another one.  
When I’m using Action / Flows / Login / Custom / From template / post-login / whitelist by user email I keep getting this error page after a login attempt.

I handle the following way:

```auto
export const GET = handleAuth({
	async callback(req: any, res: any) {
        try {
            await handleCallback(req, res);
        } catch (error) {
            return Response.redirect(
				`http://localhost:3000/api/auth/logout`,
				301 // just for testing
			)
        }
    },
	login: handleLogin({
		returnTo: `http://localhost:3000/admin`,
	}),
	'silent-login': handleLogin({
		authorizationParams: { prompt: 'none' },
	}),
	logout: handleLogout({
		returnTo: `http://localhost:3000`,
	}),
});

```

Although it calls the logout endpoint it never really logs me out. So I’m stucked in this idle place where I can’t log in neither log out properly while using this custom post-login flow.

---

<div class="post-metadata">

**Author:** ![rakesh.bitling](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rakesh.bitling/32/58421_2.png) [@rakesh.bitling](https://community.auth0.com/u/rakesh.bitling)\
**Post date:** [July 27, 2024, 4:49am UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/6 "2024-07-27T04:49:12Z")

</div>

Yes same thing happening to me. Logout is not working at all.

---

<div class="post-metadata">

**Author:** ![gabor.ottlik.hun](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gabor.ottlik.hun/32/57175_2.png) [@gabor.ottlik.hun](https://community.auth0.com/u/gabor.ottlik.hun)\
**Post date:** [August 7, 2024, 8:47pm UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/7 "2024-08-07T20:47:33Z")

</div>

This helped.

> [@Logging out completely](https://community.auth0.com/t/logging-out-completely/118940/4):
>
> Hey - that’s not the most usable solution though, as a non-persistent cookie will be removed on closing the browser, requiring a re-login if I close the tab/browser session. Also, the cookie isn’t the issue here - as I mentioned, the cookie is removed with the /api/auth/logout call, the issue is that some other magic is logging the user back in without logging in if its within a time period of the logout. For me, logout should mean logout, I don’t understand how this behaviour is useful or sec…

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 21, 2024, 8:47pm UTC](https://community.auth0.com/t/how-to-handle-access-denied-response/136668/8 "2024-08-21T20:47:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
