return username and id in login and signup page

This commit is contained in:
slawk0
2025-01-05 15:19:58 +01:00
parent 892b394836
commit 33ffc2aeb4
3 changed files with 19 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ export type Inputs = {
};
export default function Login() {
const { setAuthorized } = useContext(AuthContext);
const { setUser, setAuthorized } = useContext(AuthContext);
const [message, setMessage] = useState('');
const navigate = useNavigate();
const [IsLoading, setIsLoading] = useState<boolean>(false);
@@ -27,11 +27,12 @@ export default function Login() {
.post('/api/auth/login', data, {
withCredentials: true,
})
.then(() => {
.then((res) => {
setUser({ username: res.data.username, id: res.data.user_id });
setAuthorized(true);
setIsLoading(false);
console.log('redirecting');
navigate('/');
navigate('/chat');
})
.catch((err) => {
if (err.response) {

View File

@@ -13,7 +13,8 @@ type Inputs = {
};
export default function Signup() {
const { setAuthorized } = useContext(AuthContext);
const { setUser, setAuthorized } = useContext(AuthContext);
const {
register,
handleSubmit,
@@ -41,10 +42,11 @@ export default function Signup() {
.post(`/api/auth/signup`, data, {
withCredentials: true,
})
.then(() => {
.then((res) => {
setUser({ username: res.data.username, id: res.data.user_id });
setAuthorized(true);
setIsLoading(false);
navigate('/');
navigate('/chat');
console.log('Signed up');
})
.catch((err) => {