Making page reload after logging in

Hi, I’ve created a gated site that redirects visitors to a login page with a 401 code. The login page has the identity menu button that opens up a modal for users to sign in. Problem is once they’ve signed in, they are still stuck on the login page, and the only way to go back to the main page is by refreshing the login page.

This is because of the 401 redirect, the URL is the main page yet it’s displaying the body of the login page. I was looking into netlify functions and saw a identity-login. I’ve attempted to create a identity-login.js and included a short code:
Hoping that once a user login, the event is picked up and the above script fires, nothing actually happens.

Any advice on this so I could make the page reload once a user has logged in?

Hi @NikShafiq

Simplest method is to add the following to the login page as taken from the Usage section of the repository.

  const user = netlifyIdentity.currentUser();

  // Bind to login event
  netlifyIdentity.on('login', user => location.href = '/');