-
Notifications
You must be signed in to change notification settings - Fork 1k
"Implement password sign-in option (#1036)" #1380
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
Open
depak7
wants to merge
3
commits into
CapSoftware:main
Choose a base branch
from
depak7:feature/password-signin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
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
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 |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import { | |
| import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
| import { AnimatePresence, motion } from "framer-motion"; | ||
| import Cookies from "js-cookie"; | ||
| import { LucideArrowUpRight } from "lucide-react"; | ||
| import { KeyRound, LucideArrowUpRight } from "lucide-react"; | ||
| import Image from "next/image"; | ||
| import Link from "next/link"; | ||
| import { useRouter, useSearchParams } from "next/navigation"; | ||
|
|
@@ -40,6 +40,8 @@ export function LoginForm() { | |
| const [lastEmailSentTime, setLastEmailSentTime] = useState<number | null>( | ||
| null, | ||
| ); | ||
| const [password, setPassword] = useState(""); | ||
| const [showCredientialLogin,setShowCredientialLogin]=useState(false); | ||
| const theme = Cookies.get("theme") || "light"; | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -248,6 +250,60 @@ export function LoginForm() { | |
| e.preventDefault(); | ||
| if (!email) return; | ||
|
|
||
| if (showCredientialLogin) { | ||
| if (!email || !password) { | ||
| toast.error("Please enter email and password"); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| setLoading(true); | ||
| trackEvent("auth_started", { method: "password", is_signup: false }); | ||
|
|
||
| const res = await signIn("credentials", { | ||
| email, | ||
| password, | ||
| redirect: false, | ||
| ...(next && next.length > 0 ? { callbackUrl: next } : {}), | ||
| }); | ||
|
|
||
| setLoading(false); | ||
|
|
||
| if (res?.ok && !res?.error) { | ||
| trackEvent("auth_success", { method: "password", is_signup: false }); | ||
| router.push(next || "/"); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| // Handle specific known errors first | ||
| if (res?.error?.toLowerCase().includes("verify")) { | ||
| toast.error("Please verify your email before logging in."); | ||
| const res = await fetch("/api/auth/resend", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ email }), | ||
| }); | ||
|
|
||
| const data = await res.json(); | ||
| if (!data?.status) { | ||
| throw "Something went wrong,try other login methods"; | ||
| } | ||
| router.push(`/verify-otp?email=${encodeURIComponent(email)}&type=credientials`); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| // Otherwise generic error | ||
| toast.error("Invalid credentials – try again?"); | ||
| } catch (error) { | ||
| console.error("Credential login error:", error); | ||
| toast.error("Invalid credentials – try again?"); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Check if we're rate limited on the client side | ||
| if (lastEmailSentTime) { | ||
| const timeSinceLastRequest = | ||
|
|
@@ -309,15 +365,28 @@ export function LoginForm() { | |
| }} | ||
| className="flex flex-col space-y-3" | ||
| > | ||
| <NormalLogin | ||
| setShowOrgInput={setShowOrgInput} | ||
| email={email} | ||
| emailSent={emailSent} | ||
| setEmail={setEmail} | ||
| loading={loading} | ||
| oauthError={oauthError} | ||
| handleGoogleSignIn={handleGoogleSignIn} | ||
| /> | ||
| {showCredientialLogin ? ( | ||
| <LoginWithEmailAndPassword | ||
| email={email} | ||
| emailSent={emailSent} | ||
| setEmail={setEmail} | ||
| password={password} | ||
| setPassword={setPassword} | ||
| loading={loading} | ||
| setShowCredientialLogin={setShowCredientialLogin} | ||
| /> | ||
| ) : ( | ||
| <NormalLogin | ||
| setShowOrgInput={setShowOrgInput} | ||
| email={email} | ||
| emailSent={emailSent} | ||
| setEmail={setEmail} | ||
| loading={loading} | ||
| oauthError={oauthError} | ||
| handleGoogleSignIn={handleGoogleSignIn} | ||
| setShowCredientialLogin={setShowCredientialLogin} | ||
| /> | ||
| )} | ||
| </motion.form> | ||
| )} | ||
| </motion.div> | ||
|
|
@@ -388,6 +457,79 @@ const LoginWithSSO = ({ | |
| ); | ||
| }; | ||
|
|
||
| const LoginWithEmailAndPassword = ({ | ||
| email, | ||
| emailSent, | ||
| setEmail, | ||
| loading, | ||
| password, | ||
| setPassword, | ||
| setShowCredientialLogin | ||
| }: { | ||
| email: string; | ||
| emailSent: boolean; | ||
| setEmail: (email: string) => void; | ||
| password: string, | ||
| setPassword: (password: string) => void; | ||
| loading: boolean; | ||
| setShowCredientialLogin : (show : boolean) => void | ||
|
|
||
| }) => { | ||
| return ( | ||
| <motion.div> | ||
| <motion.div layout className="flex flex-col space-y-3"> | ||
| <MotionInput | ||
| id="email" | ||
| name="email" | ||
| autoFocus | ||
| type="email" | ||
| placeholder={emailSent ? "" : "[email protected]"} | ||
| autoComplete="email" | ||
| required | ||
| value={email} | ||
| disabled={emailSent || loading} | ||
| onChange={(e) => { | ||
| setEmail(e.target.value); | ||
| }} | ||
| /> | ||
| <MotionInput | ||
| id="password" | ||
| name="password" | ||
| autoFocus | ||
| type="password" | ||
| placeholder={emailSent ? "" : "password"} | ||
| autoComplete="password" | ||
| required | ||
| value={password} | ||
| disabled={emailSent || loading} | ||
| onChange={(e) => { | ||
| setPassword(e.target.value); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }} | ||
| /> | ||
| <MotionButton | ||
| variant="dark" | ||
| type="submit" | ||
| disabled={loading || emailSent} | ||
| icon={<FontAwesomeIcon className="mr-1 size-4" icon={faEnvelope} />} | ||
| > | ||
| Login with email | ||
| </MotionButton> | ||
| <MotionButton | ||
| variant="gray" | ||
| type="button" | ||
| className="w-full" | ||
| layout | ||
| onClick={() => setShowCredientialLogin(false)} | ||
| disabled={loading || emailSent} | ||
| > | ||
| <LucideArrowUpRight size={20} /> | ||
| Login with OTP | ||
| </MotionButton> | ||
| </motion.div> | ||
| </motion.div> | ||
| ); | ||
| }; | ||
|
|
||
| const NormalLogin = ({ | ||
| setShowOrgInput, | ||
| email, | ||
|
|
@@ -396,6 +538,7 @@ const NormalLogin = ({ | |
| loading, | ||
| oauthError, | ||
| handleGoogleSignIn, | ||
| setShowCredientialLogin | ||
| }: { | ||
| setShowOrgInput: (show: boolean) => void; | ||
| email: string; | ||
|
|
@@ -404,6 +547,7 @@ const NormalLogin = ({ | |
| loading: boolean; | ||
| oauthError: boolean; | ||
| handleGoogleSignIn: () => void; | ||
| setShowCredientialLogin : (show : boolean) => void | ||
| }) => { | ||
| const publicEnv = usePublicEnv(); | ||
|
|
||
|
|
@@ -455,7 +599,17 @@ const NormalLogin = ({ | |
| Sign up here | ||
| </Link> | ||
| </motion.p> | ||
|
|
||
| <MotionButton | ||
| variant="gray" | ||
| type="button" | ||
| className="w-full" | ||
| layout | ||
| onClick={() => setShowCredientialLogin(true)} | ||
| disabled={loading || emailSent} | ||
| > | ||
| <KeyRound size={18}/> | ||
| Login with Password | ||
| </MotionButton> | ||
| {(publicEnv.googleAuthAvailable || publicEnv.workosAuthAvailable) && ( | ||
| <> | ||
| <div className="flex gap-4 items-center mt-4 mb-4"> | ||
|
|
||
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.
Fix typo and formatting.
The variable name has a typo ("Crediential" should be "Credential") and is missing spaces around operators.
Apply this diff:
Note: This change will require updating all references to these identifiers throughout the file (lines 253, 368, 376, 387, 467, 475, 522, 553, 562, 619).
🤖 Prompt for AI Agents