Vue.js / Nuxt.js

Nuxt Authentication

Auth strategies, JWT, session management, OAuth, middleware protection, refresh tokens, CSRF

20 interview questions·
Senior
1

What is the main difference between JWT authentication and session-based authentication in Nuxt?

Answer

JWT stores authentication information client-side in a signed token, while session-based authentication stores data server-side with a session identifier in a cookie. JWT is stateless and scalable but exposes data in the token, while sessions are more secure but require server-side storage (Redis, database).

2

How to protect a Nuxt page so it's only accessible to authenticated users?

Answer

Using definePageMeta with auth middleware protects a page. The middleware checks authentication before rendering and redirects to the login page if the user is not authenticated. This approach works in both SSR and CSR, providing robust protection.

3

In an OAuth2 flow with Nuxt, what is the correct sequence of authentication steps?

Answer

The OAuth2 Authorization Code flow follows this sequence: redirect to provider (Google, GitHub), user authentication, callback with authorization code, exchange code for access token server-side. This secure sequence avoids exposing sensitive tokens to the client.

4

Why use a refresh token in addition to an access token in a JWT authentication strategy?

5

What is a CSRF attack and how to protect against it in a Nuxt application with session-based authentication?

+17 interview questions

Master Vue.js / Nuxt.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free