refactor
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user