Email Armor
User Managment

Sign Up

Let's start integrating the sign-up function from the Email Armor module into your project to provide secure and efficient user onboarding.

Configuration for signUp function

1. Integration

To start, integrate the signUp function from the Email Armor module within your API file as shown below:

import { signUp } from 'email-armor';
const response = await signUp(fullName, username, email, password, referralCode, userAgent, userRole);

2. Brief Description of Each Field

Field NameDescription
fullNameFull name of the user
usernameUsername provided by the user
emailEmail address of the user
passwordUser password (minimum length of 8 characters)
referralCodeReferral code, or pass an empty string ("") if not available
userAgentName of the user's agent (e.g., browser, device, etc.)
userRoleUser role, or pass an empty string ("") if none

3. Error Responses

StatusMessage
206Min. Password Length Must Be Greater Than 8.
400Invalid Fullname!
400Invalid username!
400Invalid Email!
400Username already exists!
400Email already exists!
400Wrong Referral Code!
401Your device is unauthorized.
500An unexpected error occurred. Please report this issue at GitHub

4. Success Response

Upon a successful account creation, you'll receive a 202 response along with the following details:

{
  id: new ObjectId('66e0fe542c1e3dc4dcb3eb01'),
  userName: 'priyalraj',
  signedJWTToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTmFtZSI6InByaXlhbHJhajk5IiwidXNlckFnZW50IjoiJDJiJDEwJExSbVFpMm11Y1RUcjlGYy9YNUpRU09sYWFNWC91eXRucEtmR2Nid0FiOFFZR3hGd3hFZEFLIiwiaWF0IjoxNzI2MDIxMjA0LCJleHAiOjE3NTc1NTcyMDR9.w-trwD9Sim4Wuqad9S8ufwGFR46fmhrlcH8gRo6tn-E',
  message: 'Account created successfully!',
  status: 202
}

5. Storing Cookies

Once you receive the 202 response, store the id, userName, and signedJWTToken in cookies. Below is an example of how to store these values using Next.js.

Note: You can use any method of cookie storage depending upon your tech stack.

const expireIn365Days = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000);
 
// Set cookies for user data: userName, id, and JWT token (expires in 365 days)
cookies().set("userName", userName, { path: "/", domain: process.env.COOKIE_DOMAIN || "localhost", expires: expireIn365Days });
cookies().set("id", response.id, { path: "/", domain: process.env.COOKIE_DOMAIN || "localhost", expires: expireIn365Days });
//@ts-expect-error: Ignore TypeScript error for setting signedJWTToken cookie
cookies().set("token", response.signedJWTToken, { path: "/", domain: process.env.COOKIE_DOMAIN || "localhost", expires: expireIn365Days });

Configuring the signIn Module

Once the signUp module is set up, proceed to configure the signIn module for user authentication and login functionality.

On this page