login.ts
488 Bytes
import { Context } from "../";
import User from "entity/User";
import * as R from "ramda";
// password를 암호화하자
export default async (
root: {},
{ input: { email, password } },
context: Context
) => {
const { connection } = context;
const userRepo = connection.getRepository(User);
const user = await userRepo.findOne({
where: {
email,
password
}
});
if (R.isNil(user)) return null;
const token = user!.id;
return { user, token };
};