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'
}
CodePudding user response:
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