From f550c5b1b2c4ee6659c291f05caab6119e10ccf8 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 13 Apr 2020 11:23:24 +0200 Subject: [PATCH] added auth/utils.ts Signed-off-by: Philip Molares Signed-off-by: David Mehren --- lib/web/auth/{utils.js => utils.ts} | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) rename lib/web/auth/{utils.js => utils.ts} (72%) diff --git a/lib/web/auth/utils.js b/lib/web/auth/utils.ts similarity index 72% rename from lib/web/auth/utils.js rename to lib/web/auth/utils.ts index fb69f08cf..793c78515 100644 --- a/lib/web/auth/utils.js +++ b/lib/web/auth/utils.ts @@ -1,11 +1,14 @@ -'use strict' +import { User } from '../../models' +import { logger } from '../../logger' -const models = require('../../models') -const logger = require('../../logger') - -exports.passportGeneralCallback = function callback (accessToken, refreshToken, profile, done) { - var stringifiedProfile = JSON.stringify(profile) - models.User.findOrCreate({ +exports.passportGeneralCallback = function callback ( + accessToken, + refreshToken, + profile, + done: (err: any, user: User | null) => void +): void { + const stringifiedProfile = JSON.stringify(profile) + User.findOrCreate({ where: { profileid: profile.id.toString() }, @@ -14,9 +17,9 @@ exports.passportGeneralCallback = function callback (accessToken, refreshToken, accessToken: accessToken, refreshToken: refreshToken } - }).spread(function (user, created) { + }).then(function ([user, _]) { if (user) { - var needSave = false + let needSave = false if (user.profile !== stringifiedProfile) { user.profile = stringifiedProfile needSave = true