Authenticated App

Build a complete application with OAuth authentication, protected routes, and session management using the Deva SDK.


What You'll Build

A React application demonstrating:

  • OAuth 2.0 + OIDC authentication with PKCE security

  • Protected routes requiring authentication

  • Public routes accessible to everyone

  • Session persistence across page refreshes

  • Auto-redirect to intended destination after login

  • User profile display and management

  • Logout handling with token revocation


Example Structure

example-authenticated-app/
├── src/
│   ├── components/
│   │   └── ProtectedRoute.tsx    # Route protection wrapper
│   ├── pages/
│   │   ├── LandingPage.tsx       # Public home page
│   │   ├── AboutPage.tsx         # Public about page
│   │   ├── LoginPage.tsx         # Login page
│   │   ├── DashboardPage.tsx     # Protected dashboard
│   │   ├── ProfilePage.tsx       # Protected profile
│   │   └── SettingsPage.tsx      # Protected settings
│   ├── App.tsx                   # Main app with routing
│   └── main.tsx                  # App entry point
└── package.json

Routes

Public Routes (accessible without login):

  • / - Landing page

  • /about - About page

  • /login - Login page

Protected Routes (require authentication):

  • /dashboard - Personal dashboard

  • /profile - User profile

  • /settings - Account settings


Code for Each Page

App.tsx - Main Application


ProtectedRoute.tsx - Route Protection


LandingPage.tsx - Home Page


AboutPage.tsx - About Page


LoginPage.tsx - Login Page


DashboardPage.tsx - Protected Dashboard


ProfilePage.tsx - User Profile


SettingsPage.tsx - Account Settings


Setup & Installation

Prerequisites

Get Deva Credentials

  1. Visit deva.mearrow-up-right and sign in

  2. Go to Settings → Apps

  3. Click Create New Application

  4. Fill in:

    • Name: My Authenticated App

    • Redirect URIs: http://localhost:5174

    • Origin URIs: http://localhost:5174

  5. Copy your Client ID

Install and Run

Open http://localhost:5174 in your browser.

Test the App

  1. Click Sign In button

  2. Authenticate with your Deva account

  3. Explore:

    • Dashboard - View your stats

    • Profile - See your user information

    • Settings - Manage preferences

  4. Click Logout to end session


Notes

  • OAuth flow uses PKCE for security

  • Tokens stored in sessionStorage (cleared on browser close)

  • Authentication state persists across page refreshes within same session

  • isReady prevents flash of incorrect auth state during initialization

  • Logout revokes tokens server-side and clears local storage

  • Redirect URI must match exactly what's configured in Deva app settings


Last updated