Skip to content

feat(auth0-fastify): use AsyncLocalStorage to track FastifyRequest and FastifyReply#39

Open
frederikprijck wants to merge 1 commit intomainfrom
feat/use-async-local-storage
Open

feat(auth0-fastify): use AsyncLocalStorage to track FastifyRequest and FastifyReply#39
frederikprijck wants to merge 1 commit intomainfrom
feat/use-async-local-storage

Conversation

@frederikprijck
Copy link
Copy Markdown
Member

@frederikprijck frederikprijck commented Nov 4, 2025

Description

This PR moves request and reply instances to Async Local Storage by using the onRequest hook. Because of this, we have global access to the request and reply instances, and we have no need to pass the request and reply instances to every single public method.

Before:

fastify.get('/', async (request, reply) => {
  const user = await fastify.auth0Client!.getUser({ request, reply });

  return reply.viewAsync('index.ejs', { isLoggedIn: !!user, user: user });
});

After:

fastify.get('/', async (request, reply) => {
  const user = await fastify.auth0Client!.getUser();

  return reply.viewAsync('index.ejs', { isLoggedIn: !!user, user: user });
});

We remain to accept both approaches, but we have marked the one where you pass request and reply as deprecated.

References

N/A

Testing

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

@frederikprijck frederikprijck force-pushed the feat/use-async-local-storage branch from b243b92 to de26997 Compare November 4, 2025 11:19
@frederikprijck frederikprijck force-pushed the chore/more-flexible-request-reply branch from c84c9fc to e6762f7 Compare November 4, 2025 11:30
@frederikprijck frederikprijck force-pushed the feat/use-async-local-storage branch 2 times, most recently from 14b6a71 to a059bf8 Compare November 4, 2025 11:35
@frederikprijck frederikprijck force-pushed the feat/use-async-local-storage branch from 95bfbe7 to 52bc34c Compare November 4, 2025 12:53
@frederikprijck frederikprijck force-pushed the feat/use-async-local-storage branch 4 times, most recently from 4f2ced8 to a54daaa Compare January 29, 2026 15:15
@frederikprijck frederikprijck force-pushed the feat/use-async-local-storage branch from a54daaa to 41e0232 Compare March 3, 2026 09:00
@frederikprijck frederikprijck changed the base branch from chore/more-flexible-request-reply to main March 3, 2026 09:00
@frederikprijck frederikprijck marked this pull request as ready for review March 3, 2026 09:18
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.

1 participant