Skip to content

Commit

Permalink
Merge pull request #24 from builtbysuraj/feat/user-auth
Browse files Browse the repository at this point in the history
Feat/user auth
  • Loading branch information
builtbysuraj authored Feb 16, 2024
2 parents 6964a21 + d018b38 commit db0f970
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
dist
13 changes: 11 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ echo '
'

# Check tsconfig standards
npm run check-types ||
npm run check-types-client ||
(
echo '
TypeScript Check Failed. ❌
Make the required changes listed above, add changes and try to commit again.
'
false;
)

npm run check-types-server ||
(
echo '
TypeScript Check Failed. ❌
Expand All @@ -17,7 +26,7 @@ npm run check-types ||


# Check ESLint Standards
npm run check-lint ||
npm run check-lint-client ||
(
echo '
ESLint Check Failed. ❌
Expand Down
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
33 changes: 29 additions & 4 deletions client/src/components/form/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios from 'axios'
import { Link } from 'react-router-dom'

import { ENV } from '@/conf'
import styles from './Form.module.css'

axios.defaults.withCredentials = true

type FormProps = {
mode: string
promptText: string
Expand All @@ -14,6 +19,21 @@ export default function From({
promptLink,
promptLinkText,
}: FormProps) {
const endpoint = mode === 'Signup' ? '/register' : '/login'

const handleSubmit = async (evt: React.FormEvent<HTMLFormElement>) => {
evt.preventDefault()
const form = evt.target as HTMLFormElement
const formData = new FormData(form)

// Extracting form values through 'name' property, in 'data'
const data = Object.fromEntries(formData)
const res = await axios.post(`${ENV.SERVER_URL}/${endpoint}`, data)
console.log(res.data)

form.reset()
}

return (
<div className={styles.formContainer}>
<div className={styles.left}>
Expand All @@ -26,16 +46,21 @@ export default function From({
</div>
</div>
<div className={styles.right}>
<form className={styles.form}>
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
<form onSubmit={handleSubmit} className={styles.form}>
<input type="text" placeholder="Username" name="username" required />
<input
type="password"
placeholder="Password"
name="password"
required
/>
<small className={styles.fromSmall}>
By continuing, you agree to Flipkart's
<span className={styles.demoLink}> Terms of Use </span>
and
<span className={styles.demoLink}> Privacy Policy.</span>
</small>
<button>{mode}</button>
<button type="submit">{mode}</button>
<p>
{promptText}{' '}
<Link to={promptLink} className={styles.demoLink}>
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/ServerStatusProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ServerStatusProvider({ children }: PropsWithChildren) {
useEffect(() => {
const checkServerStatus = async () => {
try {
const { data } = await axios.get(`${ENV.SERVER_URL}/api/v1/status`)
const { data } = await axios.get(`${ENV.SERVER_URL}/status`)

if (data.status) {
setServerStatus(data)
Expand Down
4 changes: 3 additions & 1 deletion client/src/pages/cart/components/place-order/PlaceOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare global {
}
}

axios.defaults.withCredentials = true

export default function PlaceOrder() {
const cartData = useAppSelector((state) => state.cart)
const serverStatus = useServerStatus()
Expand All @@ -36,7 +38,7 @@ export default function PlaceOrder() {
currency: 'INR',
name: 'RazorPay',
description: 'Secure payment through RazorPay',
// image: 'https://avatars.githubusercontent.com/u/25058652?v=4',
// image: '',
order_id: order.id,
callback_url: 'http://localhost:5000/api/v1/paymentverification',
notes: {
Expand Down
5 changes: 0 additions & 5 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ export default (args: ViteConfigInput) => {
generateScopedName,
},
},
server: {
proxy: {
'/api': 'http://localhost:5000',
},
},
})
}
Loading

0 comments on commit db0f970

Please sign in to comment.