Skip to content

Session not persisting #174

Answered by casualmatt
dmatthams asked this question in Q&A
Jul 18, 2023 · 2 comments · 7 replies
Discussion options

You must be logged in to vote

this should work as middleware, I will update the documentation soon.

export default defineNuxtRouteMiddleware(async (to, _from) => {
  const { fetchUser, setUser } = useDirectusAuth();
  const user = useDirectusUser();
  if (!user.value) {
    const user = await fetchUser();
    setUser(user.value);
  }
  if (!user.value) {
    return navigateTo("/login");
  }
});

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@dmatthams
Comment options

@Intevel
Comment options

@dmatthams
Comment options

@dmatthams
Comment options

Comment options

You must be logged in to vote
3 replies
@casualmatt
Comment options

Answer selected by Intevel
@Nisthar
Comment options

@Nisthar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants