Last active
December 12, 2022 21:14
-
-
Save fl0wo/fd5e30a20d3bc85a5bd7c72b5930b785 to your computer and use it in GitHub Desktop.
Integration of login stytch lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const handler = async (event:any) => { | |
// Ge the token from Stytch | |
const token = event.queryStringParameters.token; | |
const client = loadStytch(); | |
// Grant JWT | |
const response:AuthenticateResponse = await client.oauth.authenticate(token,{ | |
session_duration_minutes: 60 | |
}); | |
const userId = response.user_id; | |
const sessionId = getSafeOrThrow(response.session?.session_id,'Session id cannot be null'); | |
const tokenJwt = getSafeOrThrow(response.session_jwt,'Session session_jwt cannot be null'); | |
// Save JWT to Secrets Manager using session-id as key | |
const jwtId = await putParameterValue(wrapCodeWithPrefix(sessionId),tokenJwt); | |
// Redirect to profile front-end page | |
return { | |
statusCode: 301, | |
headers: { | |
Location: 'http://localhost:4200/profile?stytch_session_id='+sessionId | |
} | |
}; | |
}; | |
export function wrapCodeWithPrefix(code: string) { | |
return String(process.env.PARAMETER_STORE_PREFIX) + code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The integration of the login lambda can be found here