Giter Club home page Giter Club logo

Comments (14)

ottokruse avatar ottokruse commented on August 27, 2024 1

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.

fkwfung avatar fkwfung commented on August 27, 2024 1

@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.

tinti avatar tinti commented on August 27, 2024 1

Yes. Created.

#135

from amazon-cognito-passwordless-auth.

ottokruse avatar ottokruse commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

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.

GMuirDG avatar GMuirDG commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

Ok great. If you can provide a reproducible sample we'll look into this further? Cheers

from amazon-cognito-passwordless-auth.

fkwfung avatar fkwfung commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

Nice!

from amazon-cognito-passwordless-auth.

fkwfung avatar fkwfung commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

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.

tinti avatar tinti commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

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.

ottokruse avatar ottokruse commented on August 27, 2024

Closing for now

from amazon-cognito-passwordless-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.