Skip to main content

Authentication & Authorization

Sistem autentikasi dengan JWT, Google Sign-In, dan Apple Sign-In

๐ŸŽฏ Overview

Authentication adalah salah satu fitur utama dalam MStore Mobile yang menyediakan fungsionalitas untuk sistem autentikasi dengan jwt, google sign-in, dan apple sign-in.

๐Ÿ“‹ Features

  • โœ… Email/Password login
  • โœ… Google Sign-In
  • โœ… Apple Sign-In
  • โœ… JWT token management
  • โœ… Auto token refresh
  • โœ… Biometric authentication
  • โœ… Role-based access control (RBAC)

๐Ÿ—๏ธ Architecture

BLoC Implementation

BLoC: AuthBloc

Repository Pattern

๐Ÿ“ก API Integration

Endpoints

  • /api/v1/auth/login
  • /api/v1/auth/refresh-token
  • /api/v1/auth/register-device

Request/Response Examples

Get List

Response:

๐Ÿ’พ Local Database (Isar)

Schema

  • ConfigLocal (tokens)

Queries

๐Ÿ”„ Offline-First Strategy

Write Operations

  1. Save to local Isar immediately
  2. Show success to user
  3. Add to sync queue
  4. Background sync when online
  5. Update with server response

Read Operations

  1. Read from local Isar (fast)
  2. Show to user immediately
  3. Background fetch from API
  4. Update local cache if changed
  5. Notify UI if data updated

Conflict Resolution

  • Strategy: Last-write-wins
  • Timestamp: Server timestamp as source of truth
  • Logging: All conflicts logged for audit

๐ŸŽจ UI Components

Main Screen

๐Ÿงช Testing

Unit Tests

๐Ÿ“Š Performance Considerations

  • Lazy Loading: Load data on demand
  • Pagination: Implement pagination for large datasets
  • Caching: Cache frequently accessed data
  • Indexing: Use Isar indexes for fast queries
  • Background Sync: Sync in background to avoid blocking UI

๐Ÿ” Security

  • Authorization: Check user permissions before operations
  • Data Encryption: Sensitive data encrypted in Isar
  • Input Validation: Validate all user inputs
  • Audit Trail: Log all operations for audit

๐Ÿ“ฑ Platform-Specific

iOS

  • Use Cupertino widgets
  • Follow iOS HIG
  • Handle safe area insets

Android

  • Use Material widgets
  • Follow Material Design
  • Handle back button

Last Updated: October 14, 2024
Status: โœ… Production Ready