Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove with-aws-lambda example #778

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions examples/with-aws-lambda/backend/auth.js

This file was deleted.

21 changes: 0 additions & 21 deletions examples/with-aws-lambda/backend/config.js

This file was deleted.

70 changes: 70 additions & 0 deletions examples/with-aws-lambda/backend/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
import Session from "supertokens-node/recipe/session";

export function getBackendConfig() {
return {
framework: "awsLambda",
supertokens: {
connectionURI: "",
apiKey: "",
},
appInfo: {
// learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo
appName: "^{form_appName}",
apiDomain: "^{form_apiDomain}",
websiteDomain: "^{form_websiteDomain}",
apiBasePath: "^{form_apiBasePath}",
websiteBasePath: "^{form_websiteBasePath}",
apiGatewayPath: "/dev",
},
recipeList: [
ThirdPartyEmailPassword.init({
// We have provided you with development keys which you can use for testing.
// IMPORTANT: Please replace them with your own OAuth keys for production use.
providers: [
{
config: {
thirdPartyId: "google",
clients: [
{
clientId:
"1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
clientSecret: "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",
},
],
},
},
{
config: {
thirdPartyId: "github",
clients: [
{
clientId: "467101b197249757c71f",
clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd",
},
],
},
},
{
config: {
thirdPartyId: "apple",
clients: [
{
clientId: "4398792-io.supertokens.example.service",
additionalConfig: {
keyId: "7M48Y4RYDL",
privateKey:
"-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
teamId: "YWQCXGJRJL",
},
},
],
},
},
],
}),
Session.init(),
],
isInServerlessEnv: true,
};
}
34 changes: 34 additions & 0 deletions examples/with-aws-lambda/backend/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import supertokens from "supertokens-node";
import { middleware } from "supertokens-node/framework/awsLambda";
import { getBackendConfig } from "./config.mjs";
import middy from "@middy/core";
import cors from "@middy/http-cors";
import { handler as userHandler } from "./user.mjs";

supertokens.init(getBackendConfig());

export const handler = middy(
middleware((event) => {
if (event.path === "/user") {
return userHandler(event);
}

return {
body: JSON.stringify({
msg: "Hello!",
}),
statusCode: 200,
};
})
)
.use(
cors({
origin: getBackendConfig().appInfo.websiteDomain,
credentials: true,
headers: ["Content-Type", ...supertokens.getAllCORSHeaders()].join(", "),
methods: "OPTIONS,POST,GET,PUT,DELETE",
})
)
.onError((request) => {
throw request.error;
});
4 changes: 2 additions & 2 deletions examples/with-aws-lambda/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^2.5.1",
"@middy/http-cors": "^2.5.1",
"@middy/core": "^5.1.0",
"@middy/http-cors": "^5.1.0",
"supertokens-node": "latest"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use strict";
let supertokens = require("supertokens-node");
let { verifySession } = require("supertokens-node/recipe/session/framework/awsLambda");
let middy = require("@middy/core");
let cors = require("@middy/http-cors");
let { getBackendConfig } = require("./config");
let { getBackendConfig } = require("./config.mjs");

supertokens.init(getBackendConfig());

const handler = async (event, _) => {
const userHandler = async (event, _) => {
return {
statusCode: 200,
headers: {
Expand All @@ -21,7 +20,7 @@ const handler = async (event, _) => {
};
};

module.exports.handler = middy(verifySession(handler))
export const handler = middy(verifySession(userHandler))
.use(
cors({
origin: getBackendConfig().appInfo.websiteDomain,
Expand Down
21 changes: 16 additions & 5 deletions examples/with-aws-lambda/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "./App.css";
import SuperTokens, { SuperTokensWrapper } from "supertokens-auth-react";
import { getSuperTokensRoutesForReactRouterDom } from "supertokens-auth-react/ui";
import EmailPassword from "supertokens-auth-react/recipe/emailpassword";
import { EmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/emailpassword/prebuiltui";
import ThirdPartyEmailPassword from "supertokens-auth-react/recipe/thirdpartyemailpassword";
import { ThirdPartyEmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/thirdpartyemailpassword/prebuiltui";
import Session, { SessionAuth } from "supertokens-auth-react/recipe/session";
import Home from "./Home";
import { Routes, BrowserRouter as Router, Route } from "react-router-dom";
Expand All @@ -17,7 +17,7 @@ export function getDomain() {
return host;
}
export function getAPIDomain() {
return "https://0ktsu4mmb6.execute-api.us-east-1.amazonaws.com";
return "<YOUR_API_GATEWAY_ENDPOINT>";
}

SuperTokens.init({
Expand All @@ -28,7 +28,18 @@ SuperTokens.init({
apiBasePath: "/auth",
apiGatewayPath: "/dev",
},
recipeList: [EmailPassword.init(), Session.init()],
recipeList: [
ThirdPartyEmailPassword.init({
signInAndUpFeature: {
providers: [
ThirdPartyEmailPassword.Google.init(),
ThirdPartyEmailPassword.Github.init(),
ThirdPartyEmailPassword.Apple.init(),
],
},
}),
Session.init(),
],
});

function App() {
Expand All @@ -39,7 +50,7 @@ function App() {
<div className="fill">
<Routes>
{getSuperTokensRoutesForReactRouterDom(require("react-router-dom"), [
EmailPasswordPreBuiltUI,
ThirdPartyEmailPasswordPreBuiltUI,
])}
<Route
path="/"
Expand Down
Loading