#need help with this error

38 messages · Page 1 of 1 (latest)

boreal isle
#

why do i get an error with id

prisma schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}
        
model Profile {
  id String @id @default(uuid())
  userId String @unique
  name String
  imageUrl String @db.Text
  email String @db.Text

  servers Server[]
  members Member[]
  channels Channel[]

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Server {
  id String @id @default(uuid())
  name String
  imageUrl String @db.Text
  inviteCode String @db.Text

  profileId String
  profile Profile @relation(fields: [profileId], references: [id],onDelete: Cascade)

  members Member[]
  channels Channel[]

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([profileId])
}

enum MemberRole {
  ADMIN
  MODERATOR
  GUEST
}

model Member {
  id String @id @default(uuid())
  role MemberRole @default(GUEST)

  profileId String
  profile Profile @relation(fields: [profileId],references: [id],onDelete: Cascade)

  serverId String
  server Server @relation(fields: [serverId],references: [id], onDelete: Cascade)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([profileId])
  @@index([serverId])
}

enum ChannelType {
  TEXT
  AUDIO
  VIDEO
}

model Channel {
  id String @id @default(uuid())
  name String
  type ChannelType @default(TEXT)

  profileId String
  profile Profile @relation(fields: [profileId],references: [id],onDelete: Cascade)

  serverId String
  server Server @relation(fields: [serverId],references: [id], onDelete: Cascade)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([profileId])
  @@index([serverId])
}
valid lightBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

boreal isle
#

initial-profile.ts

import { currentUser, redirectToSignIn } from "@clerk/nextjs/server";
import {db} from "@/lib/db";

export const initalProfile = async () => {
    const user = await currentUser();

    if(!user) {
        return redirectToSignIn();
    }

    const profile = await db.profile.findUnique({
        where:{
            userId: user.id
        }
    });

    if(profile) {
        return profile;
    }

    const newProfile = await db.profile.create({
        data: {
            userId: user.id,
            name: `${user.firstName} ${user.lastName}`,
            imageUrl: user.imageUrl,
            email: user.emailAddresses[0].emailAddress
        }
    });

    return newProfile;
}
still widget
#

can you perhaps show us what's the error?

boreal isle
#
import { db } from "@/lib/db";
import { initalProfile } from "@/lib/initial-profile";
import { UserButton } from "@clerk/nextjs";
import { redirect } from "next/navigation";

const SetUpPage = async () => {
  const profile = await initalProfile();

  const server = await db.server.findFirst({
    where: {
      members: {
        some: {
          profileId: profile.id,
        },
      },
    },
  });

  if (server) {
    return redirect(`/servers/${server.id}`);
  }
  return (
    <div>
      <UserButton />
    </div>
  );
};

export default SetUpPage;
#

this is the inital profile

"use client";
import { currentUser, redirectToSignIn } from "@clerk/nextjs/server";
import { db } from "@/lib/db";
import { RedirectToSignIn } from "@clerk/nextjs";

export const initalProfile = async () => {
  const user = await currentUser();

  if (!user) {
    return RedirectToSignIn;
  }

  const profile = await db.profile.findUnique({
    where: {
      userId: user.id,
    },
  });

  if (profile) {
    return profile;
  }

  const newProfile = await db.profile.create({
    data: {
      userId: user.id,
      name: `${user.firstName} ${user.lastName}`,
      imageUrl: user.imageUrl,
      email: user.emailAddresses[0].emailAddress,
    },
  });

  return newProfile;
};
#

ping me on reply

still widget
#

RedirectToSignIn is a component, I don't think it should be called in a function

boreal isle
#

it seems to work

#

pls ping me

still widget
#

okay, if it's working then what's the issue? @boreal isle

boreal isle
#
import { db } from "@/lib/db";
import { initalProfile } from "@/lib/initial-profile";
import { UserButton } from "@clerk/nextjs";
import { redirect } from "next/navigation";

const SetUpPage = async () => {
  const profile = await initalProfile();

  const server = await db.server.findFirst({
    where: {
      members: {
        some: {
          profileId: profile.id,
        },
      },
    },
  });

  if (server) {
    return redirect(`/servers/${server.id}`);
  }
  return (
    <div>
      <UserButton />
    </div>
  );
};

export default SetUpPage;
still widget
#

why does initalProfile even has 'use client'. I don't think it's supposed to have it thinq

boreal isle
#

it doesnt work without that

still widget
#

then you are simply doing it wrong, what even are you trying to do?

boreal isle
#

i m using this to get the data of the inital user from the db

#

im following a tutorial for a discord clone

#

but some of his funcations are depricated

#

so i have to figure a lot of it out myself

still widget
#

so, after login you are trying to store the user data into your db if it doesn't already exists?

boreal isle
#

yes

#

i just dont get why intialprofile is not a fucntion

#

its clearly a function

still widget
#

If I am not wrong it isn't, it's a client component. I don't think you are supposed to add 'use client' to the function, it can be only added to the components.

#

I am not sure tho

boreal isle
#

intresting

#

okk so i should focus on this error i suppose

still widget
#

Yeah

boreal isle
#

yea i need to see how to use Redirect function

#

ig rest will be fine