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

$supabase in RouteMiddleware #7

Open
nosizejosh opened this issue May 24, 2022 · 1 comment
Open

$supabase in RouteMiddleware #7

nosizejosh opened this issue May 24, 2022 · 1 comment

Comments

@nosizejosh
Copy link

Hey @one-aalam,

I am moving way from using composable with @nuxt/supbase to use your model.
I have found I am unable to get the $subpabase in NuxtRouteMiddleware as precisely I could using composable.

export default defineNuxtRouteMiddleware((to, from) => {
  const exemptRegRoute = Object.keys(to.query).includes("fromEmail");
  const publicRoutes = ["signin", "signup", "forgotpass"];
  const privateRoute = !publicRoutes.includes(to.name);
  const { $supabase } = useNuxtApp()
  const user = $supabase.auth.user()
  const user = useSupabaseUser();

  if (!user.value && privateRoute && !exemptRegRoute) {
    // if not signed in and attemting to visit private route
    // reroute to login saving the current destination in the redirect query param
    return navigateTo({ name: 'signin', query: { redirect: to.path } });
  }
});

Can you suggest a way to achieve this please?

@nosizejosh
Copy link
Author

@one-aalam any suggestions how to handle this?

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

No branches or pull requests

1 participant