Last active
December 12, 2022 21:08
-
-
Save fl0wo/2d34ca925c1c9076ec116fa9432ebe26 to your computer and use it in GitHub Desktop.
Integration of register.ts
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) => { | |
// Get token from Stytch | |
const token = event.queryStringParameters.token; | |
// Get instance of client | |
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'); | |
// Register user to Database (if you want) | |
const newUserCreated:UserEntity|false = await registerUserFromStytchToDynamoFirstTime(response.user) | |
// Save the JWT on SSM using Stytch Session Id as key (one time token) | |
const jwtId = await putParameterValue(wrapCodeWithPrefix(sessionId),tokenJwt); | |
// Redirect to your front-end profile page! | |
return { | |
statusCode: 301, | |
headers: { | |
Location: 'http://localhost:4200/profile?stytch_session_id='+sessionId | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Integration of register lambda its here