-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update with-aws-lambda example
- Loading branch information
Showing
7 changed files
with
125 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword"; | ||
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters