Comments (14)
Thank you @ottokruse for this valuable stack.
Cheers mate! Thanks!
IIRC the "Dynamic require of \"stream\" is not supported"
can be solved by adding a banner to your bundling options:
bundling: {
..., // other bundling options
banner: "import{createRequire}from 'module';const require=createRequire(import.meta.url);"
}
Give that a shot?
from amazon-cognito-passwordless-auth.
@ottokruse It works after adding the banner!
Now the custom lambda can be triggered at Create Auth with both contentCreator
and emailSender
!
Great thanks!
from amazon-cognito-passwordless-auth.
Yes. Created.
from amazon-cognito-passwordless-auth.
Thanks for your interest in this solution!
Looks like you are compiling your lambda functions as common JS and we expect ESM. But changing import to default as you did should fix that and maybe we should actually change it.
If you compile your function to ESM your problem should be solved.
Otherwise, give more information on the require ESM error you are seeing?
from amazon-cognito-passwordless-auth.
It's fine by the way that CDK code targets CommonJS and your lambda code targets ESM (it's what we do too and that works fine)
from amazon-cognito-passwordless-auth.
Thanks for your response. I've tried changing import to default, as well as playing around with different code targets and have had no luck.
I have managed to get custom HTML into the magic link email, but I had to replace the createAuthChallenge lambda with my own. This is essentially a copy pasted version of this package's, but with the html changed.
from amazon-cognito-passwordless-auth.
Ok great. If you can provide a reproducible sample we'll look into this further? Cheers
from amazon-cognito-passwordless-auth.
Thank you @ottokruse for this valuable stack.
I think I am facing the same issue. Trying to customize auth with email template and SES modification, however, the mjs build from CDK for the lambda becomes common JS:
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
(Skipping the remaining code)
The way I override is to setting functionProps on Passwordless stack:
// Override email content creator
functionProps: {
createAuthChallenge: {
// Override entry, to point to custom email content creator
entry: join(__dirname, "./custom-email/create_auth_custom_email.ts"),
memorySize: 256,
runtime: cdk.aws_lambda.Runtime.NODEJS_18_X,
architecture: cdk.aws_lambda.Architecture.ARM_64,
bundling: {
format: cdk.aws_lambda_nodejs.OutputFormat.ESM,
esbuildArgs: {
"--main-fields": "module,main",
},
externalModules: ["@aws-sdk/*", "aws-lambda"],
},
environment: {
EMAIL_TEMPLATE_TABLE_NAME: emailTemplateTable.tableName,
QUEUE_URL_SES_SEND_EMAIL: sqsSesQueue.queueUrl,
},
},
},
When the auth flow is initiated at Cognito with Magic Link, the lambda will hit the following error:
{
"errorType": "Error",
"errorMessage": "Dynamic require of \"stream\" is not supported",
"stack": [
"Error: Dynamic require of \"stream\" is not supported",
" at file:///var/task/index.mjs:12:9",
" at node_modules/cbor/lib/commented.js (file:///var/task/index.mjs:2240:18)",
" at __require2 (file:///var/task/index.mjs:15:50)",
" at node_modules/cbor/lib/cbor.js (file:///var/task/index.mjs:3851:25)",
" at __require2 (file:///var/task/index.mjs:15:50)",
" at file:///var/task/index.mjs:5626:27",
" at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"
]
}
No luck on changing target build.
Appreciate if any help / advice on this.
Thanks a lot!
from amazon-cognito-passwordless-auth.
Nice!
from amazon-cognito-passwordless-auth.
Thank you @ottokruse for your prompt help!
One more question, if we need to use an API Gateway to initiate Magic Link sending, following the current Passwordless
stack. Do you recommend to use send AdminInitiateAuthCommand
then AdminRespondToAuthChallengeCommand
in order to trigger? (It will take a few sec to respond from API Gateway if waiting for whole flow to complete)
from amazon-cognito-passwordless-auth.
I need more info to think along with you. What's the context, why and how do you want to involve API Gateway? Would you mind continuing this in another issue please?
from amazon-cognito-passwordless-auth.
Thank you @ottokruse for this valuable stack.
Cheers mate! Thanks!
IIRC the
"Dynamic require of \"stream\" is not supported"
can be solved by adding a banner to your bundling options:bundling: { ..., // other bundling options banner: "import{createRequire}from 'module';const require=createRequire(import.meta.url);" }Give that a shot?
This should be at the docs. It solved my problem too.
from amazon-cognito-passwordless-auth.
Yes we should. Want to send a PR for it @tinti? Guess we should add it here: https://github.com/aws-samples/amazon-cognito-passwordless-auth/blob/main/CUSTOMIZE-AUTH.md
from amazon-cognito-passwordless-auth.
Closing for now
from amazon-cognito-passwordless-auth.
Related Issues (20)
- Passwordless.configureFromAmplify() no longer works with the latest version of Amplify (v6)
- Type error in Verifying FIDO2 Challenge Response HOT 6
- Usage of stepUpAuthenticationWithSmsOtp in plain web. HOT 5
- Feature request: HOT 1
- Amplify cli end-to-end example HOT 5
- [Question] Using Fido2 credentials for non-signin challenges HOT 1
- Prominently mention JWT/localStorage issues in FAQ -- Avoid JWT? HOT 6
- signInStatus is 'NOT_SIGNED_IN' during refresh of token HOT 3
- Dependency issue while implementing this tutorial HOT 4
- FrontEnd Shows "Unexpected End of JSON Input" HOT 8
- The example don't work corrrectly with Windows Hello through PIN authentication HOT 17
- [Feature] Provide a python package HOT 1
- Resetting state HOT 4
- Magic Link Metadata Storage HOT 8
- ReferenceError: debug is not defined HOT 1
- [Bug] Magic link abuse by authorized user HOT 9
- [Feature Request] Add OTP SMS authentication HOT 5
- Can we load logo from assets folder locally HOT 4
- Prevent users from self-edit attributes HOT 6
- [Need Help] - No "exports" main defined in ../node_modules/amazon-cognito-passwordless-auth/package.json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amazon-cognito-passwordless-auth.