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
Token Storage
Token Storage
- NEVER simpan access token di localStorage/sessionStorage
- Access token hanya di memory (Pinia store)
- Refresh token sebagai HttpOnly cookie
- Clear tokens on logout
HTTPS Only
HTTPS Only
- Semua komunikasi harus via HTTPS
- Set
Secureflag pada cookies - Use
SameSite=StrictatauLax
Token Expiration
Token Expiration
- 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
XSS Prevention
XSS Prevention
- Sanitize user input
- Use Vue’s built-in XSS protection
- Content Security Policy (CSP) headers
- Avoid
v-htmlwith user content
Next Steps
API Interceptors
Auto-refresh dan error handling
Authentication Flow
Complete auth flow diagrams