Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const verifyCredentials = async (
{ password, username: identifier }: Omit,
userGetter: (id: string) => Promise
) => {
const user: IUser = await userGetter(identifier);
if (user) {
const isValid = await bcrypt.compare(password, user.password);
if (isValid) {
return user;
}
throw new AuthenticationError("Incorrect password!");
} else {
throw new AuthenticationError("Incorrect username or email!");
}
};
export const verifyCredentials = async (
{ password, username: identifier }: Omit,
userGetter: (id: string) => Promise
) => {
const user: IUser = await userGetter(identifier);
if (user) {
const isValid = await bcrypt.compare(password, user.password);
if (isValid) {
return user;
}
throw new AuthenticationError("Incorrect password!");
} else {
throw new AuthenticationError("Incorrect username or email!");
}
};
const isAuthenticated = (userId?: string): NexusGenAllTypes['User'] => {
if (user == null || (userId != null && user.id !== userId))
throw new AuthenticationError('you must be logged in');
return user;
};