Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Data fetching keeps failing and I don't know why
Post Body

This is currently how I'm fetching data:
request.ts

interface RequestOptions {
  method?: string;
  headers?: HeadersInit;
  body?: BodyInit;
}

const apiUrl = process.env.NEXT_PUBLIC_LOCAL_HOST_API_URL;

export const request = async <T>(
  url: string,
  options: RequestOptions
): Promise<T> => {
  const response = await fetch(`${apiUrl}/${url}`, {
    method: options.method,
    headers: options.headers,
    body: options.body
  });

  return response.json();
};

auth.ts

"use server"
import { UserProfile, Register } from "@/types/auth";
import { request } from "./request";

const fetchKeys = {
  register: "account/register",
  createProfile: "api/userProfile"
};

export async function register(formData: Register) {
  console.log(formData);
  const response = await request(fetchKeys.register, {
    method: "POST",
    headers: {
      "Content-type": "application/json"
    },
    body: JSON.stringify(formData)
  });

  return response;
}

export async function createProfile(formData: UserProfile) {
  const response = await request(fetchKeys.createProfile, {
    method: "POST",
    headers: {
      "Content-type": "application/json"
    },
    body: JSON.stringify(formData)
  });
}

And here in my form I am calling it:

    try {
      const response = await register(formData);
      console.log(response);
    } catch (error) {
      console.error(error.message);
    }

It keeps returning a 500 error and I can't figure out what I'm doing wrong

Author
Account Strength
90%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
779
Link Karma
438
Comment Karma
341
Profile updated: 3 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago