Last active
March 4, 2019 08:45
-
-
Save jamesknelson/5f7faee98e3cb77b89b7413fc3b2002b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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