Skip to content

Commit

Permalink
user auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
karla-vm committed Jan 19, 2024
1 parent e2b7c59 commit ac82ffa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion services/app-api/handlers/forms/get/getFormTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import dynamoDb from "../../../libs/dynamodb-lib";
export const main = handler(async (event, context) => {
// If this invokation is a prewarm, do nothing and return.
if (event.source == "serverless-plugin-warmup") {
console.log("Warmed up!");
return null;
}

// verify whether there is a user logged in
const currentUser = await getUserCredentialsFromJwt(event);
if (!currentUser) {
throw new Error("No authorized user.");
}

const params = {
TableName: process.env.FormsTableName,
Select: "ALL_ATTRIBUTES",
Expand Down
8 changes: 7 additions & 1 deletion services/app-api/handlers/forms/post/obtainAvailableForms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dynamodbLib from "../../../libs/dynamodb-lib";
import handler from "../../../libs/handler-lib";
import { getUserCredentialsFromJwt } from "../../../libs/authorization";

/**
* Returns list of all forms based on state
Expand All @@ -9,10 +10,15 @@ import handler from "../../../libs/handler-lib";
export const main = handler(async (event, context) => {
// *** if this invocation is a pre-warm, do nothing and return
if (event.source === "serverless-plugin-warmup") {
console.log("Warmed up!");
return null;
}

// verify whether there is a user logged in
const currentUser = await getUserCredentialsFromJwt(event);
if (!currentUser) {
throw new Error("No authorized user.");
}

let data = JSON.parse(event.body);

const params = {
Expand Down
8 changes: 7 additions & 1 deletion services/app-api/handlers/forms/post/obtainFormsList.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { getUserCredentialsFromJwt } from "../../../libs/authorization";

export const main = handler(async (event, context) => {
// If this invokation is a prewarm, do nothing and return.
if (event.source === "serverless-plugin-warmup") {
console.log("Warmed up!");
return null;
}

// verify whether there is a user logged in
const currentUser = await getUserCredentialsFromJwt(event);
if (!currentUser) {
throw new Error("No authorized user.");
}

const data = JSON.parse(event.body);

const startKey = data.startKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import handler from "../../../libs/handler-lib";
import dynamoDb from "../../../libs/dynamodb-lib";
import { getUserCredentialsFromJwt } from "../../../libs/authorization";

export const main = handler(async (event, context) => {
// If this invokation is a prewarm, do nothing and return.
if (event.source == "serverless-plugin-warmup") {
console.log("Warmed up!");
return null;
}

// verify whether there is a user logged in
const currentUser = await getUserCredentialsFromJwt(event);
if (!currentUser) {
throw new Error("No authorized user.");
}

const data = JSON.parse(event.body);

const params = {
Expand Down

0 comments on commit ac82ffa

Please sign in to comment.