"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jwt_simple_1 = __importDefault(require("jwt-simple"));
const typeorm_1 = require("typeorm");
const user_1 = require("../../../entities/user");
const SECRET = '0xD58F835B69D207A76CC5F84a70a1D0d4C79dAC95';
function tokenForUser(user) {
    const timestamp = new Date().getTime();
    //sub & iat are standard JWT params. More at jwt.io.
    return jwt_simple_1.default.encode({ sub: user.id, iat: timestamp }, SECRET);
}
exports.signin = {
    async signin(_, { email, password }, context, info) {
        const repository = typeorm_1.getRepository(user_1.User);
        const user = await repository.findOne(email);
        return { token: tokenForUser(email), user: user };
    }
};
//# sourceMappingURL=signin.js.map