Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

52
Views
How to add user in javascript file?

I am working on a web app where I want to use Authmoji ( https://authmoji.com ) for user authentication.

Authmoji provided a live example with next.js for reference. ( https://next-authmoji.vercel.app )

Here's the full source code ( https://github.com/lottamus/nextjs-authmoji )

github source code ss

Here they told us A database is not included. You can use any database you want and add it in this file.

The problem is I don't know how to add database or users in this User.js file.

here is the code

    import { v4 as uuidv4 } from "uuid";

const users = [];

export async function createUser({ phoneNumber, verifyId }) {
  const createdAt = Date.now();
  const user = {
    id: uuidv4(),
    createdAt,

    phoneNumber,
    phoneNumberVerified: false,
    verifyId, // Used to look up the user later
  };

  // This is an in memory store for users, there is no data persistence without a proper DB
  users.push(user);

  return { phoneNumber, createdAt };
}

export async function verifyPhoneNumber({ verifyId, phoneNumber }) {
  // Look up user by the verifyId
  const user = users.find(
    (user) => user.verifyId === verifyId && user.phoneNumber === phoneNumber
  );

  if (user) {
    // Set their phone number as verified
    user.phoneNumberVerified = true;
    user.verifyId = null;
  }

  return user;
}

authmoji Documentation reference link ( https://docs.authmoji.com/ZG9jOjE2NTc4NDk1-quick-start )

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs