refactor
This commit is contained in:
@@ -2,13 +2,17 @@
|
|||||||
|
|
||||||
import { SignupFormSchema, loginFormSchema } from '@/app/lib/definitions';
|
import { SignupFormSchema, loginFormSchema } from '@/app/lib/definitions';
|
||||||
import { createSession, deleteSession, getSessionData } from '@/app/lib/session';
|
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() {
|
export async function logout() {
|
||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch('http://localhost/api/auth/logout', {
|
await fetch(`${API_BASE_URL}/api/auth/logout`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -39,7 +43,7 @@ export async function authorization(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { email, password } = validatedFields.data;
|
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',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: email,
|
email: email,
|
||||||
@@ -96,7 +100,7 @@ export async function registration(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { full_name, email, password } = validatedFields.data;
|
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',
|
method: 'POST',
|
||||||
body: JSON.stringify({ fullName: full_name, email, password }),
|
body: JSON.stringify({ fullName: full_name, email, password }),
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
'use server'
|
'use server'
|
||||||
import { getSessionData } from '@/app/lib/session';
|
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 FRUITS_URL = 'https://www.fruityvice.com/api/fruit/';
|
||||||
const ALL = 'all'
|
const ALL = 'all';
|
||||||
|
|
||||||
export async function fetchFruits() {
|
export async function fetchFruits() {
|
||||||
try {
|
try {
|
||||||
@@ -31,7 +35,7 @@ export async function getUserData() {
|
|||||||
const token = await getSessionData('token');
|
const token = await getSessionData('token');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`http://localhost/api/user?email=${userEmail}`, {
|
const response = await fetch(`${API_BASE_URL}/api/user?email=${userEmail}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ export default function UserMenuButton() {
|
|||||||
id="user-menu-btn"
|
id="user-menu-btn"
|
||||||
title={userData?.fullName ? userData.fullName : ''}
|
title={userData?.fullName ? userData.fullName : ''}
|
||||||
>
|
>
|
||||||
{userData?.fullName ? userData.fullName : ''}
|
{userData?.fullName ? userData.fullName[0] : ''}
|
||||||
</div>
|
</div>
|
||||||
<div className={`user-dropdown ${isOpen ? 'show' : ''}`} id="user-dropdown">
|
<div className={`user-dropdown ${isOpen ? 'show' : ''}`} id="user-dropdown">
|
||||||
<div className="user-info-header">
|
<div className="user-info-header">
|
||||||
<div className="user-avatar-large">
|
<div className="user-avatar-large">
|
||||||
{userData?.fullName ? userData.fullName : ''}
|
{userData?.fullName ? userData.fullName[0] : ''}
|
||||||
</div>
|
</div>
|
||||||
<div className="user-details">
|
<div className="user-details">
|
||||||
<div className="user-name">
|
<div className="user-name">
|
||||||
|
|||||||
Reference in New Issue
Block a user