fix(signup): signup auth (#15628)
* fix(models.user): Colocate all user methods Moved user methods/extensions into one file. Tracked down `next method called more than once` error and setting headers after their sent. Let regular error handler handle api errors as well. * feat(server.auth): Disable github account creation We are no longer allowing account creation through github * refactor(Auth): Move user identity link into models dir * feat(Disable link account login): This removes the ability to use a linked account t * feat(errorhandlers): Add opbeat, filter out handled error
This commit is contained in:
committed by
mrugesh mohapatra
parent
7805d74ea7
commit
2fcd976700
@@ -1,48 +1,10 @@
|
||||
import passport from 'passport';
|
||||
import { PassportConfigurator } from 'loopback-component-passport';
|
||||
import passportProviders from './passport-providers';
|
||||
import uuid from 'uuid';
|
||||
import { generateKey } from 'loopback-component-passport/lib/models/utils';
|
||||
|
||||
import {
|
||||
setProfileFromGithub,
|
||||
getSocialProvider,
|
||||
getUsernameFromProvider
|
||||
} from './utils/auth';
|
||||
|
||||
const passportOptions = {
|
||||
emailOptional: true,
|
||||
profileToUser(provider, profile) {
|
||||
const emails = profile.emails;
|
||||
// NOTE(berks): get email or set to null.
|
||||
// MongoDB indexs email but can be sparse(blank)
|
||||
const email = emails && emails[0] && emails[0].value ?
|
||||
emails[0].value :
|
||||
null;
|
||||
|
||||
// create random username
|
||||
// username will be assigned when camper signups for Github
|
||||
const username = 'fcc' + uuid.v4().slice(0, 8);
|
||||
const password = generateKey('password');
|
||||
let userObj = {
|
||||
username: username,
|
||||
password: password
|
||||
};
|
||||
|
||||
if (email) {
|
||||
userObj.email = email;
|
||||
}
|
||||
|
||||
if (!(/github/).test(provider)) {
|
||||
userObj[getSocialProvider(provider)] = getUsernameFromProvider(
|
||||
getSocialProvider(provider),
|
||||
profile
|
||||
);
|
||||
} else {
|
||||
userObj = setProfileFromGithub(userObj, profile, profile._json);
|
||||
}
|
||||
return userObj;
|
||||
}
|
||||
profileToUser: null
|
||||
};
|
||||
|
||||
const fields = {
|
||||
|
Reference in New Issue
Block a user