-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement recovery process, fix bugs
- Loading branch information
1 parent
b881010
commit 4a219fd
Showing
16 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,21 +29,19 @@ export class MailerService { | |
'[email protected]' | ||
) | ||
|
||
const auth = user && pass ? { auth: { user, pass } } : {} | ||
|
||
this.transporter = nodemailer.createTransport( | ||
{ | ||
host, | ||
port, | ||
secure, | ||
auth: { | ||
user, | ||
pass | ||
} | ||
...auth, | ||
debug: process.env.NODE_ENV === 'development', | ||
logger: process.env.NODE_ENV === 'development' | ||
}, | ||
{ | ||
from: { | ||
name: fromName, | ||
address: fromAddress | ||
} | ||
from: `"${fromName}" <${fromAddress}>` | ||
} | ||
) | ||
} | ||
|
@@ -56,7 +54,7 @@ export class MailerService { | |
} | ||
|
||
const templatesFolderPath = path.join(__dirname, './templates') | ||
const templatePath = path.join(templatesFolderPath, templateName) | ||
const templatePath = path.join(templatesFolderPath, `${templateName}.hbs`) | ||
|
||
const templateSource = fs.readFileSync(templatePath, 'utf8') | ||
|
||
|
@@ -83,7 +81,6 @@ export class MailerService { | |
html: html | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
throw new HttpException( | ||
'Email could not be sent', | ||
HttpStatus.INTERNAL_SERVER_ERROR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
HandleErrorOptions, | ||
Recover2FAData, | ||
auth2FARecoveryService | ||
} from '@isomera/impl' | ||
import { useFormik } from 'formik' | ||
import * as Yup from 'yup' | ||
|
||
interface Options { | ||
onSuccess?: (response: any) => void | ||
onError?: (error: any) => void | ||
userEmail?: string | ||
} | ||
|
||
export const useRecoveryHook = (options: Options) => { | ||
const { onSuccess, onError, userEmail } = options | ||
|
||
const initialValues: Recover2FAData = { | ||
code: '', | ||
email: userEmail ?? '' | ||
} | ||
|
||
const validationSchema = Yup.object({ | ||
code: Yup.string().required('2FA code is required'), | ||
email: Yup.string().email('Invalid email').required('Email is required') | ||
}) | ||
|
||
const onSubmit = async (values: Recover2FAData) => { | ||
try { | ||
const response = await auth2FARecoveryService(values) | ||
onSuccess && onSuccess(response) | ||
} catch (error) { | ||
onError && onError(error) | ||
} | ||
} | ||
|
||
const formik = useFormik({ | ||
initialValues, | ||
validationSchema, | ||
onSubmit | ||
}) | ||
|
||
return { | ||
...formik, | ||
isLoading: formik.isSubmitting | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
import useSession from '../../hooks/useSession' | ||
import { pages, useHandleErrorHook } from '@isomera/impl' | ||
import { useRecoveryHook } from '../../hooks/Recover2FAHook' | ||
|
||
export const Recovery2FAView = () => { | ||
const { loginWith2FA, user } = useSession() | ||
const navigate = useNavigate() | ||
const { handleError } = useHandleErrorHook() | ||
|
||
const onSuccess = (data: { access_token: string; refresh_token: string }) => { | ||
loginWith2FA(data.access_token, data.refresh_token) | ||
navigate(pages.dashboard.path) | ||
} | ||
|
||
const { | ||
values, | ||
handleChange, | ||
handleBlur, | ||
errors, | ||
touched, | ||
handleSubmit, | ||
isSubmitting | ||
} = useRecoveryHook({ | ||
onSuccess, | ||
onError: (error: any) => handleError(error, { view: 'recovery' }), | ||
userEmail: user?.email | ||
}) | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<div> | ||
<label htmlFor="recoveryCode">Recovery Code</label> | ||
<input | ||
id="code" | ||
name="code" | ||
type="text" | ||
onChange={handleChange} | ||
onBlur={handleBlur} | ||
value={values.code} | ||
required | ||
/> | ||
{touched.code && errors.code && <span>{errors.code}</span>} | ||
</div> | ||
<div> | ||
<button type="submit" disabled={isSubmitting}> | ||
Recover Account | ||
</button> | ||
</div> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters