diff --git a/new-lamassu-admin/src/pages/Authentication/Input2FAState.js b/new-lamassu-admin/src/pages/Authentication/Input2FAState.js index b899db26..c872c9a6 100644 --- a/new-lamassu-admin/src/pages/Authentication/Input2FAState.js +++ b/new-lamassu-admin/src/pages/Authentication/Input2FAState.js @@ -2,6 +2,7 @@ import { useMutation, useLazyQuery } from '@apollo/react-hooks' import { makeStyles } from '@material-ui/core/styles' import base64 from 'base-64' import gql from 'graphql-tag' +import * as R from 'ramda' import React, { useContext, useState } from 'react' import { useHistory } from 'react-router-dom' @@ -58,13 +59,18 @@ const Input2FAState = ({ state, dispatch }) => { const [input2FA, { error: mutationError }] = useMutation(INPUT_2FA, { onCompleted: ({ input2FA: success }) => { if (success) { - return getUserData({ + const options = { context: { headers: { - pazuz_operatoridentifier: base64.encode(state.clientField) + 'Pazuz-Operator-Identifier': base64.encode(state.clientField) } } - }) + } + return getUserData( + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], options) + : options + ) } return setInvalidToken(true) } @@ -86,7 +92,7 @@ const Input2FAState = ({ state, dispatch }) => { return } - input2FA({ + const options = { variables: { username: state.clientField, password: state.passwordField, @@ -95,10 +101,16 @@ const Input2FAState = ({ state, dispatch }) => { }, context: { headers: { - pazuz_operatoridentifier: base64.encode(state.clientField) + 'Pazuz-Operator-Identifier': base64.encode(state.clientField) } } - }) + } + + input2FA( + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], options) + : options + ) } const getErrorMsg = () => { diff --git a/new-lamassu-admin/src/pages/Authentication/LoginState.js b/new-lamassu-admin/src/pages/Authentication/LoginState.js index 8ef4e848..86470ec3 100644 --- a/new-lamassu-admin/src/pages/Authentication/LoginState.js +++ b/new-lamassu-admin/src/pages/Authentication/LoginState.js @@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles' import base64 from 'base-64' import { Field, Form, Formik } from 'formik' import gql from 'graphql-tag' +import * as R from 'ramda' import React from 'react' import * as Yup from 'yup' @@ -50,17 +51,22 @@ const LoginState = ({ state, dispatch }) => { const [login, { error: mutationError }] = useMutation(LOGIN) const submitLogin = async (username, password, rememberMe) => { - const { data: loginResponse } = await login({ + const options = { variables: { username, password }, context: { headers: { - pazuz_operatoridentifier: base64.encode(username) + 'Pazuz-Operator-Identifier': base64.encode(username) } } - }) + } + const { data: loginResponse } = await login( + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], options) + : options + ) if (!loginResponse.login) return diff --git a/new-lamassu-admin/src/pages/Authentication/Register.js b/new-lamassu-admin/src/pages/Authentication/Register.js index 10d785b1..2ad5b53c 100644 --- a/new-lamassu-admin/src/pages/Authentication/Register.js +++ b/new-lamassu-admin/src/pages/Authentication/Register.js @@ -1,8 +1,10 @@ import { useQuery, useMutation } from '@apollo/react-hooks' import { makeStyles, Grid } from '@material-ui/core' import Paper from '@material-ui/core/Paper' +// import base64 from 'base-64' import { Field, Form, Formik } from 'formik' import gql from 'graphql-tag' +import * as R from 'ramda' import React, { useReducer } from 'react' import { useLocation, useHistory } from 'react-router-dom' import * as Yup from 'yup' @@ -91,10 +93,16 @@ const Register = () => { const classes = useStyles() const history = useHistory() const token = QueryParams().get('t') + const identifier = QueryParams().get('id') ?? null const [state, dispatch] = useReducer(reducer, initialState) - const { error: queryError, loading } = useQuery(VALIDATE_REGISTER_LINK, { + const queryOptions = { + context: { + headers: { + 'Pazuz-Operator-Identifier': identifier + } + }, variables: { token: token }, onCompleted: ({ validateRegisterLink: info }) => { if (!info) { @@ -114,7 +122,14 @@ const Register = () => { dispatch({ type: 'failure' }) - }) + } + + const { error: queryError, loading } = useQuery( + VALIDATE_REGISTER_LINK, + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], queryOptions) + : queryOptions + ) const [register, { error: mutationError }] = useMutation(REGISTER, { onCompleted: ({ register: success }) => { diff --git a/new-lamassu-admin/src/pages/Authentication/Setup2FAState.js b/new-lamassu-admin/src/pages/Authentication/Setup2FAState.js index 3cbafebc..18df7d6f 100644 --- a/new-lamassu-admin/src/pages/Authentication/Setup2FAState.js +++ b/new-lamassu-admin/src/pages/Authentication/Setup2FAState.js @@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles' import base64 from 'base-64' import gql from 'graphql-tag' import QRCode from 'qrcode.react' +import * as R from 'ramda' import React, { useContext, useState } from 'react' import { useHistory } from 'react-router-dom' @@ -68,18 +69,39 @@ const Setup2FAState = ({ state, dispatch }) => { setInvalidToken(false) } - const { error: queryError } = useQuery(GET_2FA_SECRET, { + const queryOptions = { variables: { username: state.clientField, password: state.passwordField }, context: { headers: { - pazuz_operatoridentifier: base64.encode(state.clientField) + 'Pazuz-Operator-Identifier': base64.encode(state.clientField) } }, onCompleted: ({ get2FASecret }) => { setSecret(get2FASecret.secret) setOtpauth(get2FASecret.otpauth) } - }) + } + + const mutationOptions = { + variables: { + username: state.clientField, + password: state.passwordField, + rememberMe: state.rememberMeField, + codeConfirmation: twoFAConfirmation + }, + context: { + headers: { + 'Pazuz-Operator-Identifier': base64.encode(state.clientField) + } + } + } + + const { error: queryError } = useQuery( + GET_2FA_SECRET, + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], queryOptions) + : queryOptions + ) const [getUserData] = useLazyQuery(GET_USER_DATA, { onCompleted: ({ userData }) => { @@ -90,14 +112,19 @@ const Setup2FAState = ({ state, dispatch }) => { const [setup2FA, { error: mutationError }] = useMutation(SETUP_2FA, { onCompleted: ({ setup2FA: success }) => { + const options = { + context: { + headers: { + 'Pazuz-Operator-Identifier': base64.encode(state.clientField) + } + } + } success - ? getUserData({ - context: { - headers: { - pazuz_operatoridentifier: base64.encode(state.clientField) - } - } - }) + ? getUserData( + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], options) + : options + ) : setInvalidToken(true) } }) @@ -163,19 +190,11 @@ const Setup2FAState = ({ state, dispatch }) => { setInvalidToken(true) return } - setup2FA({ - variables: { - username: state.clientField, - password: state.passwordField, - rememberMe: state.rememberMeField, - codeConfirmation: twoFAConfirmation - }, - context: { - headers: { - pazuz_operatoridentifier: base64.encode(state.clientField) - } - } - }) + setup2FA( + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? R.omit(['context'], mutationOptions) + : mutationOptions + ) }} buttonClassName={classes.loginButton}> Done diff --git a/new-lamassu-admin/src/pages/UserManagement/modals/CreateUserModal.js b/new-lamassu-admin/src/pages/UserManagement/modals/CreateUserModal.js index 486d811a..aabeac38 100644 --- a/new-lamassu-admin/src/pages/UserManagement/modals/CreateUserModal.js +++ b/new-lamassu-admin/src/pages/UserManagement/modals/CreateUserModal.js @@ -1,5 +1,6 @@ import { useMutation } from '@apollo/react-hooks' import { makeStyles } from '@material-ui/core/styles' +import base64 from 'base-64' import classnames from 'classnames' import { Field, Form, Formik } from 'formik' import gql from 'graphql-tag' @@ -74,7 +75,11 @@ const CreateUserModal = ({ state, dispatch }) => { const [createUser, { error }] = useMutation(CREATE_USER, { onCompleted: ({ createRegisterToken: token }) => { - setCreateUserURL(urlResolver(`/register?t=${token.token}`)) + const queryParams = + process.env.REACT_APP_BUILD_TARGET === 'LAMASSU' + ? `t=${token.token}` + : `t=${token.token}&id=${base64.encode(usernameField)}` + setCreateUserURL(urlResolver(`/register?${queryParams}`)) } })