Skip to content

Authentication

WARNING

The authentication in the template is for demonstration purposes only; there is no database connection.

Deska uses Nuxt Auth Utils to provide a collection of authentication utilities that simplify auth handling.

Usage

You need to set the respective providers in your nuxt.config.ts.

ts
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    oauth: {
      // provider in lowercase (github, google, etc.)
      <provider>: {
        clientId: '...',
        clientSecret: '...'
      }
    }
  }
})

You can find detailed documentation here

Auth Middleware

the global middleware ./app/middleware/auth.global.ts ensures that users are correctly redirected based on their authentication status and route metadata.

  1. Public Routes (meta.public)

    • If a route is marked as public, the middleware allows access without any restrictions.
  2. Guest Routes (meta.guest)

    • If a route is marked as guest (e.g login page), but the user is already logged in, they are redirected to the homepage (/).
  3. Protected Routes (Neither meta.public Nor meta.guest)

    • All routes not marked as public or guest requires authentication.

Usage

Example login page:

js
<script lang="ts" setup>
definePageMeta({
  guest: true // Allows only non-authenticated users
})
</script>