-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: implement server-side auth API calls in signin/signup pages #38
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,16 +19,28 @@ function signin() { | |||||||||||||
| } = useForm<TSignInSchema>({ resolver: zodResolver(signInSchema) }); | ||||||||||||||
|
|
||||||||||||||
| const onSubmit = async (data: FieldValues) => { | ||||||||||||||
| if (data.email === 'abc@gamil.com') { | ||||||||||||||
| toast.error('Submitting form is failed'); | ||||||||||||||
| return; | ||||||||||||||
| try { | ||||||||||||||
| const apiUrl = import.meta.env.VITE_API_PATH ?? 'http://localhost:5000'; | ||||||||||||||
| const response = await fetch(`${apiUrl}/api/auth/email-password/signin`, { | ||||||||||||||
| method: 'POST', | ||||||||||||||
| headers: { 'Content-Type': 'application/json' }, | ||||||||||||||
| credentials: 'include', | ||||||||||||||
| body: JSON.stringify({ | ||||||||||||||
| email: data.email, | ||||||||||||||
| password: data.password, | ||||||||||||||
| }), | ||||||||||||||
| }); | ||||||||||||||
| const result = await response.json(); | ||||||||||||||
| if (!response.ok) { | ||||||||||||||
| toast.error(result.message ?? 'Sign in failed. Please check your credentials.'); | ||||||||||||||
| return; | ||||||||||||||
|
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Use a generic signin failure message. The backend contract shown here returns different messages for “email does not exist” and “invalid password”; Line 35 exposes those directly, enabling account enumeration. Keep signin errors generic on the client, and ideally align the backend response too. Suggested fix if (!response.ok) {
- toast.error(result.message ?? 'Sign in failed. Please check your credentials.');
+ toast.error('Invalid email or password.');
return;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| toast.success(result.message ?? 'Signed in successfully!'); | ||||||||||||||
| reset(); | ||||||||||||||
| navigate('/'); | ||||||||||||||
| } catch { | ||||||||||||||
| toast.error('Unable to connect to the server. Please try again later.'); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // TODO: Server-side validation | ||||||||||||||
| await new Promise((resolve) => setTimeout(resolve, 1000)); | ||||||||||||||
|
|
||||||||||||||
| reset(); | ||||||||||||||
| navigate('/'); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,16 +19,29 @@ function signin() { | |||||||||||||||||||
| } = useForm<TSignUpSchema>({ resolver: zodResolver(signUpSchema) }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const onSubmit = async (data: FieldValues) => { | ||||||||||||||||||||
| if (data.email === 'abc@gamil.com') { | ||||||||||||||||||||
| toast.error('Submitting form is failed'); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| const apiUrl = import.meta.env.VITE_API_PATH ?? 'http://localhost:5000'; | ||||||||||||||||||||
| const response = await fetch(`${apiUrl}/api/auth/email-password/signup`, { | ||||||||||||||||||||
|
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major 🧩 Analysis chain🏁 Script executed: #!/bin/bash
frontend='DevOps-Project-39/wanderlust-3tier-project/frontend'
rg -n 'VITE_API_PATH|localhost:5000|import\.meta\.env\.(DEV|PROD)' "$frontend"
fd -H '^(\.env.*|vite\.config\..*)$' "$frontend" -x sh -c '
printf "\n--- %s\n" "$1"
rg -n "VITE_API_PATH|localhost:5000|import\.meta\.env\.(DEV|PROD)" "$1" || true
' sh {}Repository: NotHarshhaa/DevOps-Projects Length of output: 1603 Fail closed when the auth API URL is missing in production Line 23 in Suggested fix- const apiUrl = import.meta.env.VITE_API_PATH ?? 'http://localhost:5000';
+ const configuredApiUrl = import.meta.env.VITE_API_PATH?.trim();
+ const apiUrl = configuredApiUrl || (import.meta.env.DEV ? 'http://localhost:5000' : '');
+ if (!apiUrl) {
+ toast.error('Authentication service is not configured.');
+ return;
+ }
const response = await fetch(`${apiUrl}/api/auth/email-password/signup`, {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||
| headers: { 'Content-Type': 'application/json' }, | ||||||||||||||||||||
| credentials: 'include', | ||||||||||||||||||||
| body: JSON.stringify({ | ||||||||||||||||||||
| name: data.username, | ||||||||||||||||||||
| email: data.email, | ||||||||||||||||||||
| password: data.password, | ||||||||||||||||||||
| }), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| const result = await response.json(); | ||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||
| toast.error(result.message ?? 'Sign up failed. Please try again.'); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| toast.success(result.message ?? 'Account created successfully!'); | ||||||||||||||||||||
| reset(); | ||||||||||||||||||||
| navigate('/'); | ||||||||||||||||||||
| } catch { | ||||||||||||||||||||
| toast.error('Unable to connect to the server. Please try again later.'); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // TODO: Server-side validation | ||||||||||||||||||||
| await new Promise((resolve) => setTimeout(resolve, 1000)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| reset(); | ||||||||||||||||||||
| navigate('/'); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
🔒 Security & Privacy | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: NotHarshhaa/DevOps-Projects
Length of output: 1603
Fail closed when the auth API URL is missing.
The fallback to
http://localhost:5000wheneverVITE_API_PATHis unset is unsafe for production. In a production build, this causes the app to attempt posting credentials to a local service on the user's machine or fail unexpectedly. The same insecure fallback pattern is found insignup-page.tsx,blog-feed.tsx,home-page.tsx,details-page.tsx, andadd-blog.tsx.Gate the
localhostfallback to dev builds only (import.meta.env.DEV) and fail safely in production by surfacing a configuration error when the endpoint is missing.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents