Merge pull request 'registracional jol navigal a loginra' (#54) from regnavigationfix into main
Reviewed-on: #54 :D
This commit was merged in pull request #54.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from "axios"
|
||||
|
||||
export const API_CONFIG = {
|
||||
baseURL: (import.meta.env.VITE_API_URL ? import.meta.env.VITE_API_URL : '') + "/api",
|
||||
baseURL: (import.meta.env.VITE_API_URL ? import.meta.env.VITE_API_URL : "") + "/api",
|
||||
wsURL: "http://localhost:3000",
|
||||
timeout: 10000,
|
||||
retryAttempts: 3,
|
||||
@@ -12,9 +12,9 @@ export const apiClient = axios.create({
|
||||
timeout: API_CONFIG.timeout,
|
||||
withCredentials: true, // Important for cookie-based auth
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
|
||||
//login
|
||||
export const login = async (username, password) => {
|
||||
@@ -36,16 +36,6 @@ export const register = async (username, email, password, fname, lname, phone) =
|
||||
}
|
||||
}
|
||||
|
||||
//verify email
|
||||
export const verifyEmail = async (token) => {
|
||||
try {
|
||||
const response = await apiClient.get(`/users/verify-email/${token}`)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Get current user's game statistics
|
||||
export const getUserStats = async () => {
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,7 @@ import Button from "../../components/Buttons/Button"
|
||||
import { motion } from "framer-motion"
|
||||
import { useState } from "react"
|
||||
import { register } from "../../api/userApi"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { useNavigate, useLocation } from "react-router-dom"
|
||||
|
||||
export default function RegisterForm() {
|
||||
const [lastname, setLastname] = useState("")
|
||||
@@ -19,6 +19,7 @@ export default function RegisterForm() {
|
||||
const [error, setError] = useState("")
|
||||
const [showErrorPopup, setShowErrorPopup] = useState(false)
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
|
||||
function validateEmail(email) {
|
||||
return /\S+@\S+\.\S+/.test(email)
|
||||
@@ -50,7 +51,15 @@ export default function RegisterForm() {
|
||||
const response = await register(username, email, password, firstname, lastname, phone)
|
||||
// Check for 201 Created status
|
||||
if (response && response.status === 201) {
|
||||
navigate("/login", { state: { success: true } })
|
||||
// Ha már a /login útvonalon van a user, a sima navigate nem biztos, hogy újraindítja a komponenst.
|
||||
// Ilyenkor előbb beállítjuk a state-et, majd kényszerítünk egy teljes oldalletöltést.
|
||||
if (location.pathname === "/login") {
|
||||
navigate("/login", { state: { success: true } })
|
||||
// teljes újratöltés, hogy a login oldal újra feldolgozza a state-et
|
||||
window.location.reload()
|
||||
} else {
|
||||
navigate("/login", { state: { success: true } })
|
||||
}
|
||||
} else {
|
||||
let msg = "Sikertelen regisztráció."
|
||||
if (response && response.data && response.data.error) {
|
||||
|
||||
Reference in New Issue
Block a user