Getting error: 'No 'Access-Control-Allow-Origin' header is present on the requested resource.' for logout route in Django/React app
I have an app using React/Django, with Auth0 for authentication. I've followed this tutorial to fix any CORS errors, and all my routes are not running into any issues, except for my logout route.
I'm creating a logout button, which will flush the user's session on Django and redirect to the Auth0 logout page as well.
urls.py
urlpatterns = [
...
path('logout/, views.logout, name = 'logout')
]
views.py
from django.contrib.auth import logout as django_logout
def logout(request):
django_logout(request)
domain = settings.AUTH0_DOMAIN
client_id = settings.AUTH0_CLIENT_ID
return_to = '127.0.0.1:8000'
return redirect(f'https://{domain}/v2/logout?client_id={client_id}&returnTo={returnTo}')
App.jsx
const App = () => {
...
const logout = async () => {
await fetch('http://127.0.0.1:8000/logout/')
}
return (
<div>
...
<button onClick={logout}>Logout</button>
<div>
)
}
When the user logs out, I'm getting a CORS error despite importing and configuring django-cors-headers
and not getting this error for any other route. Specifically, the error is No 'Access-Control-Allow-Origin' header is present on the requested resource.