PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 3, 2022

[FIXED] how can i put dummy email and password inside of node js code

 September 03, 2022     authentication, email, javascript, reactjs     No comments   

Issue

when I try to log in I have an error message "No registered admin found". I know it's because of no existing admin info. now I want to insert a dummy email and password for the admin's login how can I put that? I'm new to this react and nodejs, please anyone can help me?

this is my code:

import { hash } from "../../../core/crypto/hash.js";
import { webToken } from "../../../core/crypto/web_token.js";
import { errors } from "../../../core/classes/errors.js";

import { adminsService } from "../../admins/index.js";

export const adminLogin = async (creds) => {

try {
   const admin = await adminsService.getWithCredentials(
    creds.email.toLowerCase()
   );

if (!admin) {
  throw new errors.Authentication("No registered admin found", "Auth");
}

if (!(await hash.verify(creds.password, admin.password))) {
  throw new errors.Authentication("Password doesn't match.", "Auth");
}

const token = webToken.generate({ uid: admin.id, role: "admin" }, "10h");

return { name: admin.name, email: admin.email, token };
 } catch (error) {
  throw error;
  }
 };

this is the problem:

authentication No registered admin found
Authentication {
   type: 'authentication',
   message: 'No registered admin found',
   from: 'Auth'
 }

Solution

you probably want to use an environment variable, and you dont want to commit the file that contains the environment variable. The same pattern you would use for secrets, API keys, etc.

IE make new file: develop.env contains:

ADMIN_USERNAME={yourusername}
ADMIN_PASS={yourpass}

then add develop.env to .gitignore so its never committed and nobody sees your details. This file will exist on the server in a production environment, for now it can rest on your local machine.

Note: this can be done with regular JS objects too. .env is just how the dotenv package in js works. https://github.com/motdotla/dotenv



Answered By - Matt Pengelly
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing