Skip to main content

Core Authentication

MStore Dashboard menggunakan JWT authentication dengan pendekatan keamanan tinggi: access token disimpan di memory dan refresh token sebagai HttpOnly cookie.

Security Architecture

Token Storage Strategy

Access token tidak pernah disimpan di localStorage atau sessionStorage untuk mencegah serangan XSS.

Authentication Flow

Login Flow

Token Refresh Flow

Implementation

Auth Store

JWT Claims Interface

Auth Composable

Auth Middleware

Login Page Implementation

Role-Based Access Control

Check Role in Component

Route-Level Permission

Security Best Practices

  • NEVER simpan access token di localStorage/sessionStorage
  • Access token hanya di memory (Pinia store)
  • Refresh token sebagai HttpOnly cookie
  • Clear tokens on logout
  • Semua komunikasi harus via HTTPS
  • Set Secure flag pada cookies
  • Use SameSite=Strict atau Lax
  • Access token: short-lived (15-30 minutes)
  • Refresh token: longer-lived (7-30 days)
  • Auto-refresh sebelum expiration
  • Force re-login jika refresh token expired
  • Sanitize user input
  • Use Vue’s built-in XSS protection
  • Content Security Policy (CSP) headers
  • Avoid v-html with user content

Next Steps

API Interceptors

Auto-refresh dan error handling

Authentication Flow

Complete auth flow diagrams