Skip to content

Instantly share code, notes, and snippets.

View fl0wo's full-sized avatar
🎯
Focusing

Florian Sabani fl0wo

🎯
Focusing
View GitHub Profile
@fl0wo
fl0wo / loadStytch.ts
Last active December 12, 2022 20:54
Load Stytch client for nodejs
import {Client} from "stytch/types/lib/client";
const stytch = require("stytch");
const creds = require('../../_secrets/stytch_credentials_TEST.json');
let client:Client;
export const loadStytch = ():Client => {
if(!client) {
client = new stytch.Client({
project_id: creds.id,
@fl0wo
fl0wo / ApiRestEndpoint.ts
Last active December 12, 2022 20:12
AddPrivateEndpointsToRestApiGateway
import {NodejsFunction} from "aws-cdk-lib/aws-lambda-nodejs";
import {HttpMethod} from "aws-cdk-lib/aws-events";
export interface ApiRestEndpoint {
description: string,
id: string,
fun: NodejsFunction,
https_methods: Array<HttpMethod>,
path: string
}
@fl0wo
fl0wo / integration.ts
Created December 12, 2022 20:17
GetStytchAuthorizerIntegrationLambda
export const getStytchAuthorizerIntegrationLambda = (
stack: Construct,
id:string,
options:InfrastructureOptions) => {
const authorizerFn = new NodejsFunction(stack, id, {
entry: `${__dirname}/check_stytch_authorizer.ts`,
architecture: Architecture.ARM_64,
environment:{
}
});
@fl0wo
fl0wo / stytch-join.component.html
Created December 12, 2022 20:31
stytch-join.component.html
<div #magic_stytch_login>
</div>
@fl0wo
fl0wo / integration.ts
Created December 12, 2022 20:47
Integration of register lambda stytch
export const getStytchRegisterLambdaIntegration = (
stack: Construct,
id:string,
options:InfrastructureOptions) => {
const registerFunction = new NodejsFunction(stack, id, {
architecture: Architecture.ARM_64,
entry: `${__dirname}/register.ts`,
logRetention: RetentionDays.ONE_WEEK,
timeout: Duration.minutes(1),
@fl0wo
fl0wo / integration.ts
Created December 12, 2022 20:51
Stytch token integration and side code
export const getStytchTokenFromSessionIdLambdaIntegration = (
stack: Construct,
id:string,
options:InfrastructureOptions) => {
const getToken = new NodejsFunction(stack, id, {
architecture: Architecture.ARM_64,
entry: `${__dirname}/token.ts`,
logRetention: RetentionDays.ONE_WEEK,
timeout: Duration.minutes(1),
@fl0wo
fl0wo / integration.ts
Created December 12, 2022 21:12
Login stytch integration ts
export const getStytchLoginLambdaIntegration = (
stack: Construct,
id:string,
options:InfrastructureOptions) => {
const loginFunction = new NodejsFunction(stack, id, {
architecture: Architecture.ARM_64,
entry: `${__dirname}/login.ts`,
logRetention: RetentionDays.ONE_WEEK,
timeout: Duration.minutes(1),
@fl0wo
fl0wo / get_user.ts
Created December 12, 2022 22:06
Lambda get user to retrieve user info from Stytch User Pool AWS Lambda
export const handler = async (event:any) => {
// Get Authorization Header
const jwtToken = getSafeOrThrow(event.headers.Authorization,'Missing authorizer on private API');
// Retrieve the email from Stytch User Pool
const email = await fromJwtTokenToUserEmail(jwtToken);
// Get user from the database
const user = await getUserFromDatabase(email);
@fl0wo
fl0wo / timestream-db.ts
Created September 22, 2023 21:06
Utility method to create an AWS Timestream Database
import { RemovalPolicy } from 'aws-cdk-lib';
import { CfnDatabase, CfnTable } from 'aws-cdk-lib/aws-timestream';
import { Construct } from 'constructs';
export interface TimeStreamConstructProps {
databaseName: string;
tableName: string;
}
export class TimeStreamConstruct extends Construct {
@fl0wo
fl0wo / timestream-write-batch.ts
Created September 22, 2023 21:30
A way to batch-write records to an AWS Timestream Database
import {
_Record,
Dimension,
MeasureValue,
MeasureValueType, TimestreamWriteClient,
WriteRecordsCommand, WriteRecordsCommandOutput,
WriteRecordsRequest,
} from '@aws-sdk/client-timestream-write';
export const getInsertRecordParameterToTimeStream = (