Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make login page automatically redirect to homepage when logged in #342

Open
vinumweb opened this issue Apr 3, 2024 · 4 comments
Open

Make login page automatically redirect to homepage when logged in #342

vinumweb opened this issue Apr 3, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@vinumweb
Copy link

vinumweb commented Apr 3, 2024

Is your feature request related to a problem? Please describe.

I think it would be necessary for the login-page to automatically redirect to the hompeage when the user is already logged in. I don't understand why the user is able to access the login-page when user is already logged in...

Describe the solution you'd like

Make an included middleware that handles this, as i don't want to keep making the same middleware for each project.

Describe alternatives you've considered

I've considered making the middleware myself, but it just takes too much time for each project.

Thanks

@vinumweb vinumweb added the enhancement New feature or request label Apr 3, 2024
@Patrity
Copy link

Patrity commented Apr 9, 2024

I'd actually advocate against this. I was not a fan when the feature was added that by default it routes you to the login page. Now I find myself adding the same lines to my nuxt config every project time

	supabase: {
		redirect: false
	}

I'd prefer to handle this on my own in middleware:

export default defineNuxtRouteMiddleware(async () => {
	const user = useSupabaseUser()

	if (!user.value) {
		return navigateTo('/login')
	}
})

This is just my $0.02 though.

@rafaelmagalhaes
Copy link

You could create a global auth to check if route is login and user exist

export default defineNuxtRouteMiddleware((to) => {
  const user = useSupabaseUser();

  // if user exists and url is /login redirect to homepage
  if (user.value && to?.name === 'login') {
    return navigateTo('/');
  }
});

@vinumweb
Copy link
Author

vinumweb commented May 6, 2024

You could create a global auth to check if route is login and user exist


export default defineNuxtRouteMiddleware((to) => {

  const user = useSupabaseUser();



  // if user exists and url is /login redirect to homepage

  if (user.value && to?.name === 'login') {

    return navigateTo('/');

  }

});



I know how to make middleware's😅
I just think it would be nice to have it included.

@rafaelmagalhaes
Copy link

You could create a global auth to check if route is login and user exist


export default defineNuxtRouteMiddleware((to) => {

  const user = useSupabaseUser();



  // if user exists and url is /login redirect to homepage

  if (user.value && to?.name === 'login') {

    return navigateTo('/');

  }

});

I know how to make middleware's😅 I just think it would be nice to have it included.

I agree, it was one of first things I checked haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants