Skip to content

Instantly share code, notes, and snippets.

@fl0wo
Last active December 12, 2022 21:08
Show Gist options
  • Save fl0wo/2d34ca925c1c9076ec116fa9432ebe26 to your computer and use it in GitHub Desktop.
Save fl0wo/2d34ca925c1c9076ec116fa9432ebe26 to your computer and use it in GitHub Desktop.
Integration of register.ts
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
}
};
};
@fl0wo
Copy link
Author

fl0wo commented Dec 12, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment