Skip to content

Instantly share code, notes, and snippets.

@designdevy
Forked from jakejrichards/connect.ts
Created August 3, 2020 06:08
Show Gist options
  • Save designdevy/6a4a3ca0fd048a34c20c2b87dc55b42e to your computer and use it in GitHub Desktop.
Save designdevy/6a4a3ca0fd048a34c20c2b87dc55b42e to your computer and use it in GitHub Desktop.
// This is a sample of what the event object that gets
// passed to your connect route could look like.
// I've chosen to use an authorizer that will pass
// the userId so that I can store the connectionId with the userId
// in my database
interface APIGatewayWebsocketEvent {
methodArn: string;
queryStringParameters: {
token: string;
};
requestContext: {
eventType: string;
connectionId: string;
authorizer: {
userId: string;
};
};
}
function onConnect(event: APIGatewayWebsocketEvent) {
const {
requestContext: {
connectionId,
authorizer: { userId },
},
} = event;
// save connectionId & userId to database for further
// messaging capabilities
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment