Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth: Netlify decoder: specifically check for dev and test #1654

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/api/src/auth/decoders/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ type NetlifyContext = ClientContext & {
}

export const netlify = (token: string, req: { context: LambdaContext }) => {
// Netlify verifies and decodes the JWT before the request is passed to our Serverless
// function, so the decoded JWT is already available in production.
if (process.env.NODE_ENV !== 'development') {
// Netlify verifies and decodes the JWT before the request is passed to our
// Serverless function, so the decoded JWT is already available in production.
// For development and test we can't verify the token because we don't have
// the signing key. Just decoding the token is the best we can do to emulate
// the native Netlify experience
if (
process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'test'
) {
return jwt.decode(token)
} else {
const clientContext = req.context.clientContext as NetlifyContext
return clientContext?.user || null
} else {
// We emulate the native Netlify experience in development mode.
// We just decode it since we don't have the signing key.
return jwt.decode(token)
}
}