Redirect user to login


You can protect your authenticated routes by creating a custom middleware in your project, here is an example:

Create ./middleware/auth.ts

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");  }});

Now you can add the middleware to your pages

<script setup lang="ts">definePageMeta({  middleware: ["auth"]})</script>