registracional jol navigal a loginra #54
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
|
|
||||||
export const API_CONFIG = {
|
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",
|
wsURL: "http://localhost:3000",
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
retryAttempts: 3,
|
retryAttempts: 3,
|
||||||
@@ -12,9 +12,9 @@ export const apiClient = axios.create({
|
|||||||
timeout: API_CONFIG.timeout,
|
timeout: API_CONFIG.timeout,
|
||||||
withCredentials: true, // Important for cookie-based auth
|
withCredentials: true, // Important for cookie-based auth
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
"Content-Type": "application/json",
|
||||||
}
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
//login
|
//login
|
||||||
export const login = async (username, password) => {
|
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
|
// Get current user's game statistics
|
||||||
export const getUserStats = async () => {
|
export const getUserStats = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import Button from "../../components/Buttons/Button"
|
|||||||
import { motion } from "framer-motion"
|
import { motion } from "framer-motion"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { register } from "../../api/userApi"
|
import { register } from "../../api/userApi"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate, useLocation } from "react-router-dom"
|
||||||
|
|
||||||
export default function RegisterForm() {
|
export default function RegisterForm() {
|
||||||
const [lastname, setLastname] = useState("")
|
const [lastname, setLastname] = useState("")
|
||||||
@@ -19,6 +19,7 @@ export default function RegisterForm() {
|
|||||||
const [error, setError] = useState("")
|
const [error, setError] = useState("")
|
||||||
const [showErrorPopup, setShowErrorPopup] = useState(false)
|
const [showErrorPopup, setShowErrorPopup] = useState(false)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const location = useLocation()
|
||||||
|
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
return /\S+@\S+\.\S+/.test(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)
|
const response = await register(username, email, password, firstname, lastname, phone)
|
||||||
// Check for 201 Created status
|
// Check for 201 Created status
|
||||||
if (response && response.status === 201) {
|
if (response && response.status === 201) {
|
||||||
|
// 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 } })
|
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 {
|
} else {
|
||||||
let msg = "Sikertelen regisztráció."
|
let msg = "Sikertelen regisztráció."
|
||||||
if (response && response.data && response.data.error) {
|
if (response && response.data && response.data.error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user