This commit is contained in:
smanylov
2025-12-02 17:46:12 +07:00
parent a8b7495d1e
commit 431b576d41
3 changed files with 16 additions and 8 deletions
+8 -4
View File
@@ -2,13 +2,17 @@
import { SignupFormSchema, loginFormSchema } from '@/app/lib/definitions';
import { createSession, deleteSession, getSessionData } from '@/app/lib/session';
import { redirect } from 'next/navigation'
import { redirect } from 'next/navigation';
const API_BASE_URL = process.env.NODE_ENV === 'development'
? 'http://localhost'
: '';
export async function logout() {
const token = await getSessionData('token');
try {
await fetch('http://localhost/api/auth/logout', {
await fetch(`${API_BASE_URL}/api/auth/logout`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
@@ -39,7 +43,7 @@ export async function authorization(
try {
const { email, password } = validatedFields.data;
const response = await fetch('http://localhost/api/auth/login', {
const response = await fetch(`${API_BASE_URL}/api/auth/login`, {
method: 'POST',
body: JSON.stringify({
email: email,
@@ -96,7 +100,7 @@ export async function registration(
try {
const { full_name, email, password } = validatedFields.data;
const response = await fetch('http://localhost/api/auth/register', {
const response = await fetch(`${API_BASE_URL}/api/auth/register`, {
method: 'POST',
body: JSON.stringify({ fullName: full_name, email, password }),
headers: {
+6 -2
View File
@@ -1,8 +1,12 @@
'use server'
import { getSessionData } from '@/app/lib/session';
const API_BASE_URL = process.env.NODE_ENV === 'development'
? 'http://localhost'
: '';
const FRUITS_URL = 'https://www.fruityvice.com/api/fruit/';
const ALL = 'all'
const ALL = 'all';
export async function fetchFruits() {
try {
@@ -31,7 +35,7 @@ export async function getUserData() {
const token = await getSessionData('token');
try {
const response = await fetch(`http://localhost/api/user?email=${userEmail}`, {
const response = await fetch(`${API_BASE_URL}/api/user?email=${userEmail}`, {
method: 'GET',
headers: {
"Content-Type": "application/json",
+2 -2
View File
@@ -45,12 +45,12 @@ export default function UserMenuButton() {
id="user-menu-btn"
title={userData?.fullName ? userData.fullName : ''}
>
{userData?.fullName ? userData.fullName : ''}
{userData?.fullName ? userData.fullName[0] : ''}
</div>
<div className={`user-dropdown ${isOpen ? 'show' : ''}`} id="user-dropdown">
<div className="user-info-header">
<div className="user-avatar-large">
{userData?.fullName ? userData.fullName : ''}
{userData?.fullName ? userData.fullName[0] : ''}
</div>
<div className="user-details">
<div className="user-name">