Skip to content

refactor(examples): use SDK requiresAuth instead of self-defined requireSession - #17

Merged
frederikprijck merged 1 commit into
mainfrom
examples-use-requires-auth
Jun 22, 2026
Merged

frederikprijck merged 1 commit into
mainfrom
examples-use-requires-auth

Conversation

@frederikprijck

Copy link
Copy Markdown
Member

Description

The web examples each defined a local requireSession middleware that duplicated a subset of the SDK's requiresAuth(). This replaces it with requiresAuth() exported from @auth0/auth0-express.

requiresAuth() is a superset of the old helper:

  • Redirects HTML requests to the configured login path with returnTo
  • Returns 401 for JSON/API requests
  • Respects the login route configured via client options

Examples updated

  • example-express-web
  • example-express-dynamic-app-base-url
  • example-express-mcd

example-express-api already used requiresAuth from @auth0/auth0-express-api and is unchanged.

Testing

  • All three examples build cleanly (npm run build)

…ireSession

The web examples each defined a local requireSession middleware that
duplicated a subset of the SDK's requiresAuth(). Replace it with
requiresAuth() from @auth0/auth0-express, which additionally returns 401
for JSON requests and respects the configured login path.
@frederikprijck
frederikprijck merged commit d4c19ea into main Jun 22, 2026
6 checks passed
frederikprijck added a commit that referenced this pull request Jul 9, 2026
…ireSession (#17)

The web examples each defined a local requireSession middleware that
duplicated a subset of the SDK's requiresAuth(). Replace it with
requiresAuth() from @auth0/auth0-express, which additionally returns 401
for JSON requests and respects the configured login path.
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