小编Fel*_*ipe的帖子

无法使用 forEach 循环遍历 HTMLCollection

我试图为每个类名为 的元素分配一个单击事件director__card--iconBox。我选择这些元素的方式是通过getElementsByClassName. background-color在编写当前代码后,我正在测试将其父 div应用于红色的函数。最终目标是能够翻转 div 并显示稍后出现的 div 的背面。

const toggleButton = document.getElementsByClassName("director__card--iconBox");

toggleButton.forEach((el) =>
  el.addEventListener("click", (event) => {
    const card = event.target.parentElement.querySelector(".director__card");
    card.classList.toggle("open");
  })
);



Run Code Online (Sandbox Code Playgroud)

我正在取回一个 HTMLCollection。我的想法是,由于 HTMLCollection,这不会起作用?我尝试过 querySelectorAll 返回节点列表,但 NodeList 返回空。

html javascript dom

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

下一个身份验证凭据提供程序 JWT/会话回调

我在将令牌传递给会话回调时遇到一些困难。我的最终目标是将登录用户的数据发送到客户端。最初我只是发回用户的电子邮件,但现在我想将用户的用户名和姓名与电子邮件一起发送。通过遵循文档,我们必须传递 JWT 和 Session 回调,以便我们的开发人员能够访问令牌中的更多数据。目前,在我的 JWT 回调中,我能够记录用户数据,非常棒。然而,当我尝试在会话回调中记录数据时,我得到一个空的 {}。非常感谢任何提示。先感谢您。

import NextAuth from "next-auth/next";
import CredentialsProvider from "next-auth/providers/credentials";

// Helper Functions
import {
  connectToDatabase,
  comparePasswords,
} from "../../helper/HelperFunctions";

export default NextAuth({
  session: { jwt: true },
  providers: [
    CredentialsProvider({
      async authorize(credentials) {
        const client = await connectToDatabase();

        const userCollection = client.db().collection("users");

        const user = await userCollection.findOne({
          email: credentials.email,
        });

        // const userInfo = {
        //   firstName: user.firstName,
        //   lastName: user.lastName,
        //   email: user.email,
        //   userName: user.userName,
        // };

        // console.log(userInfo);

        if (!user) …
Run Code Online (Sandbox Code Playgroud)

authentication session jwt next.js next-auth

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

标签 统计

authentication ×1

dom ×1

html ×1

javascript ×1

jwt ×1

next-auth ×1

next.js ×1

session ×1