//get one cat by ID from db function getOne(id) { return db("cats") .where({ id }) .first(); }
passport.deserializeUser((id, done) => { db("users") .where({ id }) .first() .then((user) => { // check if user returned, if not invalidate existing cookies if (user) { done(null, user); } else { //this invalidates existing sessions if no user returned. done(null, false); } }) .catch((err) => { done(err, null); }); });
async function getUserSubscription(userId, appType) { if (!appType) return undefined; const row = await knex('subscriptions') .where({ user_id: userId, app: appType }) .select(['start_date', 'end_date', 'product_id', 'is_cancelled']) .orderBy('start_date', 'desc') .first(); if (!row) return undefined; return { startDate: row.start_date, endDate: row.end_date, productId: row.product_id, isCancelled: !!row.is_cancelled, type: 'iap', }; }
passport.use( 'login-user', new LocalStrategy(options, (username, password, done) => { // check to see if the username exists db('users') .where('username', '=', username) .first() .then(user => { if (!user) { return done(null, false); } if (!authHelper.comparePass(password, user.password)) { return done(null, false); } return done(null, user); }) .catch(err => done(err)); }) );
.where('username', '=', username) .orWhere('email', '=', email) .first() .then((row) => { if (row) {
.returning('id') .where('address', '=', address) .first() .then((rows) => { if (rows) {
function findUser(body) { return db('users') .where({ username: body.username }) .first(); }