forked from OurProjectsCombined/chat-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
253 additions
and
26 deletions.
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 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
This file contains 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
This file contains 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
Empty file.
This file contains 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,51 @@ | ||
import React, { useState } from 'react' | ||
import { toast } from 'react-hot-toast'; | ||
|
||
const useSignup = () => { | ||
const [loading, setLoading] = useState(false); | ||
|
||
const signup = async ({fullName, username, password, confirmPassword, gender}) => { | ||
const success = handleInputErrors({fullName, username, password, confirmPassword, gender}); | ||
if(!success) return; | ||
|
||
setLoading(true); | ||
try { | ||
const res = await fetch('/api/auth/signup', { | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
body: JSON.stringify({fullName, username, password, confirmPassword, gender}), | ||
}) | ||
|
||
const data = await res.json(); | ||
console.log(data); | ||
|
||
} catch (error) { | ||
toast.error(error.message) | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
return {loading, signup}; | ||
}; | ||
|
||
|
||
export default useSignup; | ||
|
||
function handleInputErrors({fullName, username, password, confirmPassword, gender}) { | ||
if(!fullName || !username || !password || !confirmPassword || !gender) { | ||
toast.error('Please fill in all fields'); | ||
return false; | ||
} | ||
|
||
if (password !== confirmPassword) { | ||
toast.error('Passwords do not match'); | ||
return false; | ||
} | ||
|
||
if (password.length < 6) { | ||
toast.error('Password must be at least 6 characters'); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { StrictMode } from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import './index.css' | ||
import App from './App.jsx' | ||
import { StrictMode } from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import "./index.css"; | ||
import App from "./App.jsx"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
|
||
createRoot(document.getElementById('root')).render( | ||
createRoot(document.getElementById("root")).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode>, | ||
) | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter> | ||
</StrictMode> | ||
); |
This file contains 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
This file contains 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.