Skip to content

Instantly share code, notes, and snippets.

@jamesknelson
Last active March 4, 2019 08:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesknelson/5f7faee98e3cb77b89b7413fc3b2002b to your computer and use it in GitHub Desktop.
Save jamesknelson/5f7faee98e3cb77b89b7413fc3b2002b to your computer and use it in GitHub Desktop.
import { map, redirect, route } from 'navi'
function UpdatePasswordForm({ submitErrors }) {
return (
<Form
method='post'
submitErrors={submitErrors}
validate={value =>
value.password !== value.passwordConfirmation &&
{
passwordConfirmation: 'This should match your password',
}
}
>
<h1>Need a new Password?</h1>
<Form.Errors />
<Form.Field
label='New password'
name='password'
type='password'
required
/>
<Form.Field
label='And again'
name='passwordConfirmation'
type='password'
/>
<Form.SubmitButton>
Request a new password
</Form.SubmitButton>
</Form>
)
}
let route = map(async ({ body, context, method, mountpath }) => {
if (!context.currentUser) {
return redirect('/login?redirectTo='+encodeURIComponent(mountpath))
}
if (method === 'post') {
try {
await context.firebase.auth.currentUser.updatePassword(body.password);
return redirect('/')
}
catch (error) {
return route({
view: <UpdatePasswordForm submitErrors={error.message} />
})
}
}
return route({
view: <UpdatePasswordForm />
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment