小编Saj*_*ain的帖子

导入或要求不适用于 aws lamda

我正在 aws 上编写 lambda 函数。我想在用户注册到我的 mongodb 数据库后发送用户数据。我使用“预验证”方法触发了 lambda 函数。但是,“我收到此错误”预身份验证失败,错误为找不到从 /var/task/index.mjs 导入的包“aws-sdk”。”

我的 lambda 函数代码:

import AWS  from 'aws-sdk'
import {MongoClient} from 'mongodb'

exports.handler = async (event) => {
 try{
     // Retrieve the user data from the event object
  const userData = event.request.userAttributes;

  // Connect to the MongoDB database
  const client = await MongoClient.connect("database url", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });
  const db = client.db("Cluster0");
  const collection = db.collection("users");

  // Insert the user data into the collection
  await collection.insertOne(userData);

  // Close …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb amazon-web-services node.js aws-lambda

4
推荐指数
1
解决办法
4409
查看次数

我想在下一个身份验证中将 JWT 令牌发送到我的后端

我正在使用下一个js。我正在使用 next-auth 进行身份验证。这是一个 MERN 堆栈项目。

问题:如何获取 jwt 令牌并使用 next-auth 和 axios 将其发送到我的后端。

(session.jwt) is giving me undefined.
Run Code Online (Sandbox Code Playgroud)

这是我的 nextauth.js 文件:

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import { MongoDBAdapter } from '@next-auth/mongodb-adapter';
import clientPromise from '../../../lib/mongodb';

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
  ],
  callbacks: {
    session: async ({ session, user }) => {
      if (session?.user) {
        session.user.id = user.id;
      }
      return session;
    },
  },
  adapter: MongoDBAdapter(clientPromise),
  secret: process.env.JWT_SECRET,
  session: {
    jwt: true,
    maxAge: …
Run Code Online (Sandbox Code Playgroud)

javascript authentication mern next.js next-auth

1
推荐指数
1
解决办法
6179
查看次数