我写了一个service
方法,该方法允许user
在我的再验证API
中获得身份验证。 get方法调用此方法:
public async auth(email: string, password: string): Promise<Customer> {
let connection = await DatabaseProvider.getConnection();
const customer = await connection.getRepository(Customer).findOne({ email });
try {
let isMatch = await bcrypt.compare(password, customer!.password);
if (!isMatch) throw 'Password did not match';
Promise.resolve(customer);
} catch (err) {
Promise.reject('Authentication failed');
}
}
我得到的问题是:
声明的类型既不是'void'也不是'any'的函数必须返回值。
似乎Promise.resolve(customer)
不返回任何内容,我也尝试给return
加上前缀,但存在相同的问题
public async auth(email: string, password: string): Promise<Customer> {
let connection = await DatabaseProvider.getConnection();
const customer = await connection.getRepository(Customer).findOne({ email });
let isMatch = await bcrypt.compare(password, customer!.password);
if (!isMatch) throw 'Password did not match';
if(customer)
return customer;
throw 'Customer is undefined';
}