-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
202 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const ServerIdPage = async () => { | ||
return <div>serveridpage</div>; | ||
}; | ||
|
||
export default ServerIdPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { NextResponse } from 'next/server'; | ||
import { MemberRole } from '@prisma/client'; | ||
|
||
import { currentProfile } from '@/lib/current-profile'; | ||
import { db } from '@/lib/db'; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const { name, imageUrl } = await req.json(); | ||
const profile = await currentProfile(); | ||
|
||
if (!profile) { | ||
return new NextResponse('Unauthorized', { status: 401 }); | ||
} | ||
|
||
const server = await db.server.create({ | ||
data: { | ||
profileId: profile.id, | ||
name, | ||
imageUrl, | ||
inviteCode: uuidv4(), | ||
channels: { | ||
create: [{ name: 'general', profileId: profile.id }], | ||
}, | ||
members: { | ||
create: [{ profileId: profile.id, role: MemberRole.ADMIN }], | ||
}, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(server); | ||
} catch (error) { | ||
console.log('[SERVERS_POST]', error); | ||
return new NextResponse('Internal Error', { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { auth } from '@clerk/nextjs'; | ||
|
||
import { db } from '@/lib/db'; | ||
|
||
export const currentProfile = async () => { | ||
const { userId } = auth(); | ||
|
||
if (!userId) { | ||
return null; | ||
} | ||
|
||
const profile = await db.profile.findUnique({ | ||
where: { | ||
userId, | ||
}, | ||
}); | ||
|
||
return profile; | ||
}; |
Oops, something went wrong.