Skip to content

Performance lag due to Supabase getUser calls in Next.js middleware #20905

Answered by charislam
filigreti asked this question in Questions
Discussion options

You must be logged in to vote

Hi @filigreti! Moved this to a discussion because the instructions and SDK work as intended, but there are certain mitigations you can try:

  1. If you have routes that don't require a Supabase call, you can update the matcher to exclude them.
  2. You can also validate the JWT yourself in middleware, rather than calling the Supabase Auth server to do it. We generally don't recommend this because the performance benefit may not be worth the security risks. It is very important that you:
  • Validate the JWT by checking the signature. Do not just rely on what the cookie tells you, because anyone can send any cookie to you that they want.
  • Never leak the JWT signing key on the client. This can be easy …

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@Kylar13
Comment options

@j4w8n
Comment options

@zineanteoh
Comment options

@kangmingtay
Comment options

@j4w8n
Comment options

Answer selected by kangmingtay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
9 participants
Converted from issue

This discussion was converted from issue #20901 on January 31, 2024 17:03.