Skip to content

Conversation

Copy link

Copilot AI commented Oct 6, 2025

Overview

This PR converts the BuildEvents application from a server-side rendered (SSR) web application to a Single-Page Application (SPA) with MSAL (Microsoft Authentication Library) for Azure AD authentication.

Problem Statement

The application architecture needed clarification regarding whether it should be a Single-Page Application or a Web Application, and which authentication pattern to use:

  • Single-Page Application (SPA): Runs entirely in browser, uses MSAL for client-side authentication, is a public client unable to store secrets
  • Web Application: Runs code on server, maintains sessions, is a confidential client that can store secrets

This PR implements the SPA architecture with MSAL React, following Microsoft's recommended pattern for browser-based applications.

Changes Made

1. SPA Mode Configuration

Changed react-router.config.ts to enable SPA mode:

export default {
  ssr: false,  // Enables SPA mode
} satisfies Config;

2. MSAL Authentication Integration

  • Added dependencies: @azure/msal-react and @azure/msal-browser
  • Created store/authConfig.ts: MSAL configuration with environment variable support
  • Updated store/useuser.tsx: Now uses useMsal() hook instead of server-side /.auth/me endpoint
  • Created app/entry.client.tsx: Custom entry point that wraps the app with MsalProvider

3. Client-Side Data Fetching

Converted all server-side loaders to client-side data fetching using useEffect:

  • app/routes/home.tsx - Design configuration loaded on client
  • app/routes/app.tsx - Design configuration loaded on client
  • app/favicon.tsx - Converted to static component

4. Documentation

  • web/docs/AUTHENTICATION.md: Complete Azure AD setup guide
  • web/docs/SPA_CONVERSION_SUMMARY.md: Technical implementation details
  • web/.env.example: Environment variable template
  • Updated web/README.md: Describes the SPA architecture

Authentication Architecture

Feature Implementation
Framework React with React Router (SPA mode)
Auth Library MSAL React
Client Type Public Client
Token Management ID tokens for sign-in, Access tokens for APIs
Local Development Uses default user (no Azure AD required)

Local Development

For localhost development, the application uses a default user automatically:

const defaultUser = {
  key: "seth-juarez",
  name: "Seth Juarez",
  email: "[email protected]",
  avatar: "/images/people/seth-juarez.jpg"
};

This allows immediate development without requiring Azure AD configuration.

Production Setup

To enable Azure AD authentication in production:

  1. Register app in Azure AD as Single-page application (SPA)
  2. Configure environment variables:
    VITE_AZURE_CLIENT_ID=your-client-id
    VITE_AZURE_AUTHORITY=https://login.microsoftonline.com/tenant-id
    VITE_AZURE_REDIRECT_URI=https://your-domain.com
  3. Deploy static files from build/client directory

Screenshots

Home Page (SPA Mode):
Home Page

App Page (showing default user for localhost):
App Page

Benefits

  • Simpler Deployment: Static files only, no Node.js server required
  • CDN-Friendly: Can be deployed to any CDN for global distribution
  • Industry Standard: Follows Microsoft's recommended SPA authentication pattern
  • Better Caching: Static assets can be aggressively cached
  • Client-Side Routing: Instant page transitions

Testing

  • ✅ TypeScript compilation successful
  • ✅ Build generates proper SPA output with isSpaMode: true
  • ✅ Application loads correctly in browser
  • ✅ Default user displayed for localhost
  • ✅ All routes functional

Documentation

References

Original prompt

Is this a single-page application or a web application? Single-page application (SPA)
A single-page application runs entirely in the browser and fetches page data (HTML, CSS, and JavaScript) dynamically or at application load time. It can call web APIs to interact with back-end data sources.

Because a SPA's code runs entirely in the browser, it's considered a public client that's unable to store secrets securely.

Language / framework Project on
GitHub Package Getting
started Sign in users Access web APIs
React MSAL React2 msal-react Quickstart Library can request ID tokens for user sign-in. Library can request access tokens for protected web APIs.
JavaScript MSAL.js2 msal-browser Quickstart Library can request ID tokens for user sign-in. Library can request access tokens for protected web APIs.
Angular MSAL Angular2 msal-angular Quickstart Library can request ID tokens for user sign-in. Library can request access tokens for protected web APIs.
Web application
A web application runs code on a server that generates and sends HTML, CSS, and JavaScript to a user's web browser to be rendered. The user's identity is maintained as a session between the user's browser (the front end) and the web server (the back end).

Because a web application's code runs on the web server, it's considered a confidential client that can store secrets securely.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add user authentication for single-page application Convert to Single-Page Application (SPA) with MSAL Authentication Oct 6, 2025
Copilot AI requested a review from fosteramanda October 6, 2025 23:43
Copilot finished work on behalf of fosteramanda October 6, 2025 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants