generated from warmachine028/github-super-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a5605be
commit 142e562
Showing
9 changed files
with
83 additions
and
14 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 |
---|---|---|
@@ -1,29 +1,27 @@ | ||
DUMMY_DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" | ||
|
||
# Vercel | ||
POSTGRES_URL=<Your POSTGRES_URL> | ||
POSTGRES_PRISMA_URL=<Your POSTGRES_PRISMA_URL> | ||
POSTGRES_URL_NO_SSL=<Your POSTGRES_URL_NO_SSL> | ||
POSTGRES_URL_NON_POOLING=<Your POSTGRES_URL_NON_POOLING> | ||
POSTGRES_USER=<Your POSTGRES_USER> | ||
POSTGRES_HOST=<Your POSTGRES_HOST> | ||
POSTGRES_PASSWORD=<Your POSTGRES_PASSWORD> | ||
POSTGRES_DATABASE=<Your POSTGRES_DATABASE> | ||
# Prisma | ||
PULSE_API_KEY=<Your PULSE_API_KEY> | ||
OPTIMIZELY_API_KEY=<Your OPTIMIZELY_API_KEY> | ||
CRON_SECRET=<Your CRON_SECRET> | ||
|
||
# Neon | ||
DATABASE_PRISMA_URL=<Your DATABASE_PRISMA_URL> | ||
DATABASE_URL=<Your DATABASE_URL> | ||
DATABASE_URL_UNPOOLED=<Your DATABASE_URL_UNPOOLED> | ||
ID=<Your ID> | ||
HOST=<Your HOST> | ||
NEON_API=<Your NEON_API> | ||
|
||
# Optional | ||
NEON_API=<Your NEON_API> | ||
VERCEL_TOKEN=<Your VERCEL_TOKEN> | ||
|
||
# UploadThing | ||
UPLOADTHING_TOKEN=<Your UPLOADTHING_TOKEN> | ||
NEXT_PUBLIC_UPLOADTHING_APP_ID=<Your NEXT_PUBLIC_UPLOADTHING_APP_ID> | ||
|
||
# Other | ||
CRON_SECRET=<Your CRON_SECRET> | ||
|
||
# Stream | ||
NEXT_PUBLIC_STREAM_KEY=<Your NEXT_PUBLIC_STREAM_KEY> | ||
STREAM_SECRET=<Your STREAM_SECRET> |
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
Empty file.
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,21 @@ | ||
import { validateRequest } from '@/auth' | ||
import { streamServerClient } from '@/lib' | ||
import type { NextRequest } from 'next/server' | ||
|
||
export async function GET(req: NextRequest) { | ||
try { | ||
const { user } = await validateRequest() | ||
|
||
if (!user) { | ||
return Response.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
const expirationTime = Math.floor(Date.now() / 1000) + 60 * 60 // 1 hour | ||
const issuedAt = Math.floor(Date.now() / 1000) - 60 // current time in seconds | ||
const token = streamServerClient.createToken(user.id, expirationTime, issuedAt) | ||
|
||
return Response.json({ token }) | ||
} catch (error) { | ||
console.error(error) | ||
return Response.json({ error: 'Internal server 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
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,41 @@ | ||
import { useEffect, useState } from 'react' | ||
import { kyInstance } from '@/lib/ky' | ||
import { useSession } from '.' | ||
import { StreamChat } from 'stream-chat' | ||
|
||
const useInitializeChatClient = () => { | ||
const { user } = useSession() | ||
const [chatClient, setChatClient] = useState<StreamChat | null>(null) | ||
|
||
useEffect(() => { | ||
const client = StreamChat.getInstance(process.env.NEXT_PUBLIC_STREAM_KEY as string) | ||
client | ||
.connectUser( | ||
{ | ||
id: user.id, | ||
username: user.userName, | ||
name: user.displayName, | ||
image: user.avatarUrl | ||
}, | ||
async () => | ||
kyInstance | ||
.get('/api/get-token') | ||
.json<{ token: string }>() | ||
.then((data) => data.token) | ||
) | ||
.catch((err) => console.error('Failed to connect to chat client', err)) | ||
.then(() => setChatClient(client)) | ||
|
||
return () => { | ||
setChatClient(null) | ||
client | ||
.disconnectUser() | ||
.catch((err) => console.error('Failed to disconnect user', err)) | ||
.then(() => console.log('Connection closed')) | ||
} | ||
}, [user.id, user.userName, user.displayName, user.avatarUrl]) | ||
|
||
return chatClient | ||
} | ||
|
||
export default useInitializeChatClient |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { cn, formatRelativeDate } from './utils' | ||
export * from './utils' | ||
export { default as kyInstance } from './ky' | ||
export { default as prisma } from './prisma' | ||
export { default as streamServerClient } from './stream' |
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,8 @@ | ||
import { StreamChat } from 'stream-chat' | ||
|
||
const streamServerClient = StreamChat.getInstance( | ||
process.env.NEXT_PUBLIC_STREAM_KEY as string, | ||
process.env.STREAM_SECRET as string | ||
) | ||
|
||
export default streamServerClient |