Repository navigation
Implement reset password #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
155 changes: 155 additions & 0 deletions
155
src/app/[country]/[locale]/(storefront)/account/forgot-password/page.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| "use client"; | ||
|
|
||
| import { CircleAlert, CircleCheck, Mail } from "lucide-react"; | ||
| import Link from "next/link"; | ||
| import { usePathname } from "next/navigation"; | ||
| import { useState } from "react"; | ||
| import { Alert, AlertDescription } from "@/components/ui/alert"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardDescription, | ||
| CardFooter, | ||
| CardHeader, | ||
| CardTitle, | ||
| } from "@/components/ui/card"; | ||
| import { Field, FieldLabel } from "@/components/ui/field"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { requestPasswordReset } from "@/lib/data/customer"; | ||
| import { extractBasePath } from "@/lib/utils/path"; | ||
|
|
||
| export default function ForgotPasswordPage() { | ||
| const pathname = usePathname(); | ||
| const basePath = extractBasePath(pathname); | ||
|
|
||
| const [email, setEmail] = useState(""); | ||
| const [submitting, setSubmitting] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const [submitted, setSubmitted] = useState(false); | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| setError(null); | ||
| setSubmitting(true); | ||
|
|
||
| try { | ||
| const origin = window.location.origin; | ||
| const redirectUrl = `${origin}${basePath}/account/reset-password`; | ||
| await requestPasswordReset(email, redirectUrl); | ||
| setSubmitted(true); | ||
| } catch { | ||
| setError("Something went wrong. Please try again."); | ||
| } finally { | ||
| setSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| if (submitted) { | ||
| return ( | ||
| <div className="max-w-md mx-auto px-4 sm:px-6 lg:px-8 py-16"> | ||
| <Card> | ||
| <CardHeader className="text-center"> | ||
| <div className="mx-auto w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mb-2"> | ||
| <CircleCheck className="w-6 h-6 text-green-600" /> | ||
| </div> | ||
| <CardTitle>Check your email</CardTitle> | ||
| <CardDescription> | ||
| If an account exists for <strong>{email}</strong>, we've sent | ||
| password reset instructions. | ||
| </CardDescription> | ||
| </CardHeader> | ||
|
|
||
| <CardContent className="space-y-4"> | ||
| <div className="flex items-start gap-3 text-sm text-gray-600"> | ||
| <Mail className="w-5 h-5 mt-0.5 flex-shrink-0 text-gray-400" /> | ||
| <p> | ||
| The link in the email will expire in 15 minutes. Check your spam | ||
| folder if you don't see it. | ||
| </p> | ||
| </div> | ||
|
|
||
| <Button | ||
| variant="outline" | ||
| className="w-full" | ||
| onClick={() => { | ||
| setSubmitted(false); | ||
| setEmail(""); | ||
| }} | ||
| > | ||
| Try a different email | ||
| </Button> | ||
| </CardContent> | ||
|
|
||
| <CardFooter className="justify-center"> | ||
| <Link | ||
| href={`${basePath}/account`} | ||
| className="text-sm text-primary hover:text-primary/70 font-medium" | ||
| > | ||
| Back to sign in | ||
| </Link> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="max-w-md mx-auto px-4 sm:px-6 lg:px-8 py-16"> | ||
| <Card> | ||
| <CardHeader className="text-center"> | ||
| <CardTitle>Reset your password</CardTitle> | ||
| <CardDescription> | ||
| Enter your email and we'll send you a link to reset your | ||
| password. | ||
| </CardDescription> | ||
| </CardHeader> | ||
|
|
||
| <CardContent> | ||
| <form onSubmit={handleSubmit} className="space-y-4"> | ||
| {error && ( | ||
| <Alert variant="destructive"> | ||
| <CircleAlert /> | ||
| <AlertDescription>{error}</AlertDescription> | ||
| </Alert> | ||
| )} | ||
|
|
||
| <Field> | ||
| <FieldLabel htmlFor="email">Email</FieldLabel> | ||
| <Input | ||
| type="email" | ||
| id="email" | ||
| name="email" | ||
| autoComplete="email" | ||
| value={email} | ||
| onChange={(e) => setEmail(e.target.value)} | ||
| required | ||
| placeholder="you@example.com" | ||
| /> | ||
| </Field> | ||
|
|
||
| <div className="w-full"> | ||
| <Button | ||
| type="submit" | ||
| disabled={submitting} | ||
| size="lg" | ||
| className="w-full" | ||
| > | ||
| {submitting ? "Sending..." : "Send reset link"} | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| </CardContent> | ||
|
|
||
| <CardFooter className="justify-center"> | ||
| <Link | ||
| href={`${basePath}/account`} | ||
| className="text-sm text-primary hover:text-primary/70 font-medium" | ||
| > | ||
| Back to sign in | ||
| </Link> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
For@spree/nextv0.10.5, what is the exact failure behavior of requestPasswordReset(email, redirectUrl): does it throw, or return an object like { success: false, error }?💡 Result:
I couldn’t verify the exact v0.10.5 behavior from public docs/source via web search (the Spree docs page for
@spree/nextdoesn’t documentrequestPasswordReset, and I couldn’t retrieve the v0.10.5 package source itself from an authoritative public location in this environment). (spreecommerce.org)What I can say confidently is:
@spree/storefront-api-v2-sdk) explicitly does not throw and instead returns a “result object” you must inspect (isSuccess()/isFail(),fail()), but that statement is about that SDK, not@spree/next. (app.unpkg.com)So for
@spree/next@0.10.5specifically, you’ll need to confirm by checking the installed package’s typings/implementation locally:node_modules/@spree/next/dist/**/*.d.ts(or equivalent) — see whetherrequestPasswordReset(...)returnsPromise<void>/Promise<...>and whether it documents throwing.node_modules/@spree/next/dist/**/*.js— search forfunction requestPasswordResetand see if it doesif (!res.ok) throw ...vsreturn { success: false, error }.If you paste the
requestPasswordResetfunction (or its.d.tssignature) from@spree/next@0.10.5, I can tell you precisely whether it throws or returns a{ success: false, error }-style object.Citations:
🏁 Script executed:
Repository: spree/storefront
Length of output: 134
🏁 Script executed:
Repository: spree/storefront
Length of output: 5935
🏁 Script executed:
rg "requestPasswordReset" -t ts -t tsx -A 3 -B 3Repository: spree/storefront
Length of output: 87
🏁 Script executed:
Repository: spree/storefront
Length of output: 42
🏁 Script executed:
Repository: spree/storefront
Length of output: 86
🏁 Script executed:
Repository: spree/storefront
Length of output: 1767
🏁 Script executed:
Repository: spree/storefront
Length of output: 42
🏁 Script executed:
Repository: spree/storefront
Length of output: 42
🏁 Script executed:
Repository: spree/storefront
Length of output: 42
🏁 Script executed:
Repository: spree/storefront
Length of output: 231
🏁 Script executed:
Repository: spree/storefront
Length of output: 94
🏁 Script executed:
Repository: spree/storefront
Length of output: 5109
🏁 Script executed:
Repository: spree/storefront
Length of output: 186
🏁 Script executed:
Repository: spree/storefront
Length of output: 42
🏁 Script executed:
Repository: spree/storefront
Length of output: 247
🏁 Script executed:
Repository: spree/storefront
Length of output: 3823
🏁 Script executed:
Repository: spree/storefront
Length of output: 3937
🏁 Script executed:
cat -n src/contexts/AuthContext.tsx | head -150Repository: spree/storefront
Length of output: 4239
🏁 Script executed:
Repository: spree/storefront
Length of output: 1767
🏁 Script executed:
Repository: spree/storefront
Length of output: 550
🏁 Script executed:
Repository: spree/storefront
Length of output: 1142
🏁 Script executed:
Repository: spree/storefront
Length of output: 235
🏁 Script executed:
Repository: spree/storefront
Length of output: 3764
Check the
requestPasswordResetresult for success before showing confirmation.At lines 39-40,
setSubmitted(true)is called unconditionally afterawait requestPasswordReset(...). The reset-password page (lines 80-88) treatsresetPasswordas returning a result object with{ success, error }and checksif (result.success). SincerequestPasswordResetis wrapped identically toresetPasswordin the customer module, it likely returns the same result object. IfrequestPasswordResetreturns{ success: false }, the try-catch will not catch it, and users will see a false "Check your email" success message.Align the error handling with the reset-password page pattern:
🤖 Prompt for AI Agents