Skip to content

Commit fef3d67

Browse files
RengaN02Seefaaa
andauthored
Adds authorization and adds friends, messages, rounds, tickets, bans pages for authorized visitors (#9)
[#14](psychonaut-station/api#14) Siteye giriş yapma sistemi ekler. Giriş yapan kullanıcılar hesaplarını byond hesabına site aracılıgıyla baglayabilir ve kendilerine ait bazı oyun verilerini görebilir --------- Co-authored-by: Sefa <50076109+Seefaaa@users.noreply.github.com>
1 parent 2c1217d commit fef3d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2927
-487
lines changed

.env.example

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
PRODUCTION_URL=https://ss13.tr
22
CDN_URL=https://cdn.ss13.tr
33
SERVER_GITHUB=https://github.com/psychonaut-station/PsychonautStation
4+
45
API_URL=https://api.ss13.tr
5-
API_KEY=
6+
API_KEY=abCdEfGhIjKlMnOpQrStUvWxYz123456
7+
8+
AUTH_DISCORD_ID=1234567890
9+
AUTH_DISCORD_SECRET=abcdefghijklmnopqrstuvwxyz123456
10+
11+
NEXTAUTH_SECRET=abCdEfGhIjKlMnOpQrStUvWxYz1234567890abCdEfGhIjKlMnOpQrStUvWxYz123456
12+
NEXTAUTH_URL=https://ss13.tr
13+
14+
VERIFY_WEBHOOK_URL=https://discord.com/api/webhooks/*

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"**/error.tsx": "${dirname}/error.tsx",
66
"**/not-found.tsx": "${dirname}/not-found.tsx",
77
"**/layout.tsx": "${dirname}/layout.tsx",
8-
}
8+
},
9+
"tailwindCSS.experimental.classRegex": [
10+
["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
11+
]
912
}

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ WORKDIR /app
33

44
FROM base AS deps
55
RUN apk add --no-cache libc6-compat
6-
COPY package.json bun.lock .
6+
COPY package.json bun.lock ./
77
RUN bun install --frozen-lockfile
88

99
FROM base AS builder
@@ -27,6 +27,11 @@ ENV CDN_URL=https://cdn.ss13.tr
2727
ENV SERVER_GITHUB=https://github.com/psychonaut-station/PsychonautStation
2828
ENV API_URL=https://api.ss13.tr
2929
ENV API_KEY=hello
30+
ENV AUTH_DISCORD_ID=1234567890
31+
ENV AUTH_DISCORD_SECRET=ABCDEFGHI
32+
ENV NEXTAUTH_SECRET=herhangi_bir_rastgele_uzun_karakter_dizisi
33+
ENV NEXTAUTH_URL=https://ss13.tr
34+
ENV VERIFY_WEBHOOK_URL=https://discord.com/api/webhooks/*
3035

3136
USER bun
3237
EXPOSE 3000
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import NextAuth from 'next-auth';
2+
3+
import { authOptions } from '@/app/lib/auth';
4+
5+
const handler = NextAuth(authOptions);
6+
7+
export { handler as GET, handler as POST };

app/api/autocomplete/ckey/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { type NextRequest, NextResponse } from 'next/server';
22
import * as z from 'zod';
33

4-
import headers from '@/app/lib/headers';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
56

6-
const endpoint = process.env.API_URL + '/v2/autocomplete/ckey';
7+
const endpoint = `${process.env.API_URL}/v2/autocomplete/ckey`;
78

89
const QuerySchema = z.object({
910
ckey: z.string().min(1).max(32),
@@ -17,7 +18,7 @@ export async function GET(request: NextRequest) {
1718
}
1819

1920
try {
20-
const response = await fetch(`${endpoint}?ckey=${data.ckey}`, { headers, next: { revalidate: 3_600 } });
21+
const response = await get(buildUrl(endpoint, { ckey: data.ckey }), 3_600);
2122

2223
if (!response.ok) {
2324
throw new Error('Failed to fetch');

app/api/events/citations/route.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { type NextRequest, NextResponse } from 'next/server';
22
import * as z from 'zod';
33

4-
import headers from '@/app/lib/headers';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
56

6-
const endpoint = process.env.API_URL + '/v2/events/citations';
7+
const endpoint = `${process.env.API_URL}/v2/events/citations`;
78

89
const QuerySchema = z.object({
910
fetch_size: z.string().refine(val => {
@@ -27,10 +28,10 @@ export async function GET(request: NextRequest) {
2728
return new NextResponse('Bad Request', { status: 400 });
2829
}
2930

30-
const { fetch_size: fetchSize, page } = data;
31+
const { fetch_size, page } = data;
3132

3233
try {
33-
const response = await fetch(`${endpoint}?fetch_size=${fetchSize}&page=${page}`, { headers, next: { revalidate: 3_600 } });
34+
const response = await get(buildUrl(endpoint, { fetch_size, page }), 3_600);
3435

3536
if (!response.ok) {
3637
throw new Error('Failed to fetch');

app/api/events/crimes/route.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { type NextRequest, NextResponse } from 'next/server';
22
import * as z from 'zod';
33

4-
import headers from '@/app/lib/headers';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
56

6-
const endpoint = process.env.API_URL + '/v2/events/crimes';
7+
const endpoint = `${process.env.API_URL}/v2/events/crimes`;
78

89
const QuerySchema = z.object({
910
fetch_size: z.string().refine(val => {
@@ -27,10 +28,10 @@ export async function GET(request: NextRequest) {
2728
return new NextResponse('Bad Request', { status: 400 });
2829
}
2930

30-
const { fetch_size: fetchSize, page } = data;
31+
const { fetch_size, page } = data;
3132

3233
try {
33-
const response = await fetch(`${endpoint}?fetch_size=${fetchSize}&page=${page}`, { headers, next: { revalidate: 3_600 } });
34+
const response = await get(buildUrl(endpoint, { fetch_size, page }), 3_600);
3435

3536
if (!response.ok) {
3637
throw new Error('Failed to fetch');

app/api/events/deaths/route.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { type NextRequest, NextResponse } from 'next/server';
22
import * as z from 'zod';
33

4-
import headers from '@/app/lib/headers';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
56

6-
const endpoint = process.env.API_URL + '/v2/events/deaths';
7+
const endpoint = `${process.env.API_URL}/v2/events/deaths`;
78

89
const QuerySchema = z.object({
910
fetch_size: z.string().refine(val => {
@@ -27,10 +28,10 @@ export async function GET(request: NextRequest) {
2728
return new NextResponse('Bad Request', { status: 400 });
2829
}
2930

30-
const { fetch_size: fetchSize, page } = data;
31+
const { fetch_size, page } = data;
3132

3233
try {
33-
const response = await fetch(`${endpoint}?fetch_size=${fetchSize}&page=${page}`, { headers, next: { revalidate: 3_600 } });
34+
const response = await get(buildUrl(endpoint, { fetch_size, page }), 3_600);
3435

3536
if (!response.ok) {
3637
throw new Error('Failed to fetch');

app/api/player/bans/route.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NextResponse } from 'next/server';
2+
3+
import { getAuthSession } from '@/app/lib/auth';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
6+
7+
const endpoint = `${process.env.API_URL}/v2/player/ban`;
8+
9+
export async function GET() {
10+
const session = await getAuthSession();
11+
const ckey = session?.user?.ckey;
12+
13+
if (!ckey) {
14+
return new NextResponse('Unauthorized', { status: 401 });
15+
}
16+
17+
try {
18+
const response = await get(buildUrl(endpoint, { ckey }), 3_600);
19+
20+
if (!response.ok) {
21+
throw new Error('Failed to fetch');
22+
}
23+
24+
return NextResponse.json(await response.json());
25+
} catch {
26+
return new NextResponse('Internal Server Error', { status: 500 });
27+
}
28+
}

app/api/player/ckey/route.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NextResponse } from 'next/server';
2+
3+
import { getAuthSession } from '@/app/lib/auth';
4+
import { buildUrl } from '@/app/lib/data';
5+
import { get } from '@/app/lib/headers';
6+
7+
const endpoint = `${process.env.API_URL}/v2/player/discord`;
8+
9+
export async function GET() {
10+
const session = await getAuthSession();
11+
const id = session?.user?.id;
12+
13+
if (!id) {
14+
return new NextResponse('Unauthorized', { status: 401 });
15+
}
16+
17+
try {
18+
const response = await get(buildUrl(endpoint, { discord_id: id }), 3_600);
19+
20+
if (!response.ok) {
21+
throw new Error('Failed to fetch');
22+
}
23+
24+
return NextResponse.json(await response.json());
25+
} catch {
26+
return new NextResponse('Internal Server Error', { status: 500 });
27+
}
28+
}

0 commit comments

Comments
 (0)