diff --git a/auth-server/migrations/20180917160913_users.js b/auth-server/migrations/20180917160913_users.js index 1cc8daf71..83e78dddd 100644 --- a/auth-server/migrations/20180917160913_users.js +++ b/auth-server/migrations/20180917160913_users.js @@ -2,7 +2,7 @@ exports.up = (knex) => { return knex.schema.createTable('users', (table) => { table.increments('id').primary(); - table.string('email').unique().notNullable(); + table.string('email').nullable(); table.string('password').notNullable(); table.string('salt').notNullable(); table.string('username').unique().notNullable(); diff --git a/auth-server/src/model/User.ts b/auth-server/src/model/User.ts index 943f6ab3b..e94e5730e 100644 --- a/auth-server/src/model/User.ts +++ b/auth-server/src/model/User.ts @@ -42,8 +42,8 @@ export default class User extends Model { properties: { id: { type: 'integer' }, username: { type: 'string', minLength: 1, maxLength: 255 }, - email: { type: 'string', minLength: 1, maxLength: 255 }, - name: { type: 'string', minLength: 1, maxLength: 512 }, + email: { type: 'string', maxLength: 255 }, + name: { type: 'string', maxLength: 512 }, email_verified: { type: 'boolean' } } }; diff --git a/auth-server/src/resolvers/mutation/signup.ts b/auth-server/src/resolvers/mutation/signup.ts index c75488734..24e82d8d3 100644 --- a/auth-server/src/resolvers/mutation/signup.ts +++ b/auth-server/src/resolvers/mutation/signup.ts @@ -15,7 +15,7 @@ interface argsType { export default async (parent, { email, password, username, name }: argsType, ctx: Context): Promise => { - if (!validateEmail(email)) { + if (email && !validateEmail(email)) { throw new UserInputError(messages.INVALID_EMAIL); } @@ -31,4 +31,4 @@ export default async (parent, { email, password, username, name }: argsType, ctx const { user, token, refreshToken } = await authServiceInstance.SignUp(email, password, username, name); setRefreshTokenCookie(ctx.res, refreshToken); return { user, token }; -}; \ No newline at end of file +}; diff --git a/auth-server/src/schema/mutation/signup.ts b/auth-server/src/schema/mutation/signup.ts index 1baf6465b..504c15edd 100644 --- a/auth-server/src/schema/mutation/signup.ts +++ b/auth-server/src/schema/mutation/signup.ts @@ -1,8 +1,8 @@ export default ` signup( - email: String! + email: String password: String! username: String! name: String ): LoginResponse -`; \ No newline at end of file +`; diff --git a/auth-server/src/services/auth.ts b/auth-server/src/services/auth.ts index afcf79d1d..824b43aa3 100644 --- a/auth-server/src/services/auth.ts +++ b/auth-server/src/services/auth.ts @@ -100,10 +100,12 @@ export default class AuthService { throw new ForbiddenError(messages.USERNAME_ALREADY_EXISTS); } - existing = await User - .query() - .where('email', email) - .first(); + if (email) { + existing = await User + .query() + .where('email', email) + .first(); + } if (existing) { throw new ForbiddenError(messages.USER_EMAIL_ALREADY_EXISTS); @@ -124,17 +126,19 @@ export default class AuthService { email_verified: false }); - const verifyToken = await EmailVerificationToken - .query() - .allowInsert('[token, user_id, valid]') - .insert({ - token: uuid(), - user_id: user.id, - valid: true - }); - - // send verification email in background - sendVerificationEmail(user, verifyToken); + if (email) { + const verifyToken = await EmailVerificationToken + .query() + .allowInsert('[token, user_id, valid]') + .insert({ + token: uuid(), + user_id: user.id, + valid: true + }); + + // send verification email in background + sendVerificationEmail(user, verifyToken); + } return { user: { diff --git a/front-end/src/generated/auth-graphql.tsx b/front-end/src/generated/auth-graphql.tsx index caee2522c..1235c66f2 100644 --- a/front-end/src/generated/auth-graphql.tsx +++ b/front-end/src/generated/auth-graphql.tsx @@ -137,7 +137,7 @@ export type MutationResetPasswordArgs = { export type MutationSignupArgs = { - email: Scalars['String'], + email?: Maybe, password: Scalars['String'], username: Scalars['String'], name?: Maybe @@ -211,7 +211,7 @@ export type UserFragment = ( ); export type SignupMutationVariables = { - email: Scalars['String'], + email?: Maybe, password: Scalars['String'], username: Scalars['String'], name?: Maybe @@ -280,7 +280,7 @@ export const UserFragmentDoc = gql` } `; export const SignupDocument = gql` - mutation SIGNUP($email: String!, $password: String!, $username: String!, $name: String) { + mutation SIGNUP($email: String, $password: String!, $username: String!, $name: String) { signup(email: $email, password: $password, username: $username, name: $name) { user { ...user diff --git a/front-end/src/generated/graphql.tsx b/front-end/src/generated/graphql.tsx index a4d173e7d..a1f5a1cec 100644 --- a/front-end/src/generated/graphql.tsx +++ b/front-end/src/generated/graphql.tsx @@ -830,7 +830,7 @@ export type MutationResetPasswordArgs = { export type MutationSignupArgs = { - email: Scalars['String'], + email?: Maybe, name?: Maybe, password: Scalars['String'], username: Scalars['String'] @@ -1241,7 +1241,7 @@ export type Mutation_RootResetPasswordArgs = { export type Mutation_RootSignupArgs = { - email: Scalars['String'], + email?: Maybe, name?: Maybe, password: Scalars['String'], username: Scalars['String'] diff --git a/front-end/src/screens/SignupForm/index.tsx b/front-end/src/screens/SignupForm/index.tsx index ced3d6e4f..fe9ff5aaa 100644 --- a/front-end/src/screens/SignupForm/index.tsx +++ b/front-end/src/screens/SignupForm/index.tsx @@ -28,7 +28,7 @@ const SignupForm = ({ className }:Props): JSX.Element => { const handleSubmitForm = (data:Record):void => { const { email, name, password, username } = data; - if (username && email && password){ + if (username && password){ signupMutation({ variables: { email, @@ -40,7 +40,9 @@ const SignupForm = ({ className }:Props): JSX.Element => { .then(({ data }) => { if (data && data.signup && data.signup.token && data.signup.user) { handleLoginUser({ token: data.signup.token, user: data.signup.user }, currentUser); - setModal({ content: 'We sent you an email to verify your address. Click on the link in the email.' ,title: 'You\'ve got some mail' }); + if (email) { + setModal({ content: 'We sent you an email to verify your address. Click on the link in the email.' ,title: 'You\'ve got some mail' }); + } history.push('/'); }} @@ -76,10 +78,8 @@ const SignupForm = ({ className }:Props): JSX.Element => { className={errors.name ? 'error' : ''} name='name' placeholder='Firstname Lastname' - ref={register({ minLength: 3, required: true })} type='text' /> - {errors.name && {messages.VALIDATION_NAME_ERROR}} @@ -90,8 +90,7 @@ const SignupForm = ({ className }:Props): JSX.Element => { name='email' placeholder='john@doe.com' ref={register({ - pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i, - required: true + pattern: /^[A-Z0-9_'%=+!`#~$*?^{}&|-]+([.][A-Z0-9_'%=+!`#~$*?^{}&|-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)+$/i })} type='text' /> diff --git a/front-end/src/services/auth-queries.ts b/front-end/src/services/auth-queries.ts index 30115eec6..c3020ecec 100644 --- a/front-end/src/services/auth-queries.ts +++ b/front-end/src/services/auth-queries.ts @@ -11,7 +11,7 @@ const USER_FRAGMENT = gql` `; export const SIGNUP = gql` - mutation SIGNUP($email: String!, $password: String!, $username: String!, $name: String) { + mutation SIGNUP($email: String, $password: String!, $username: String!, $name: String) { signup(email: $email, password: $password, username:$username, name:$name){ user { ...user diff --git a/front-end/src/util/messages.ts b/front-end/src/util/messages.ts index 5de9bb56c..4448e9eb4 100644 --- a/front-end/src/util/messages.ts +++ b/front-end/src/util/messages.ts @@ -1,8 +1,7 @@ export default { VALIDATION_CONTENT_ERROR: 'Did you forget to add content?', VALIDATION_EMAIL_ERROR: 'You need to provide a valid email!', - VALIDATION_NAME_ERROR: 'You need to provide a name with at least 3 characters!', VALIDATION_PASSWORD_ERROR: 'You need to specify a password with at least 6 characters!', VALIDATION_TITLE_ERROR: 'Did you forget to add a title?', VALIDATION_USERNAME_ERROR: 'You need to specify a username with at least 3 characters!' -}; \ No newline at end of file +};