Skip to content

Commit ea9936a

Browse files
committed
fix: Switch to Web Standard redirects
1 parent f1d368b commit ea9936a

7 files changed

Lines changed: 15 additions & 22 deletions

File tree

.github/workflows/npm-beta-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ jobs:
2323
run: bun install --frozen-lockfile
2424
- name: Build Project
2525
run: bun run build
26-
- uses: JS-DevTools/npm-publish@v3
26+
- uses: JS-DevTools/npm-publish@v4
2727
with:
28-
token: ${{ secrets.NPM_TOKEN }}
2928
access: "public"
3029
provenance: true
3130
tag: "beta"

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
run: bun install --frozen-lockfile
2121
- name: Build Project
2222
run: bun run build
23-
- uses: JS-DevTools/npm-publish@v3
23+
- uses: JS-DevTools/npm-publish@v4
2424
with:
25-
token: ${{ secrets.NPM_TOKEN }}
2625
access: "public"
2726
provenance: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dist"
99
],
1010
"license": "WTFPL",
11-
"version": "1.0.7",
11+
"version": "1.0.8",
1212
"type": "module",
1313
"keywords": [
1414
"auth",

src/redirect.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { type NextRequest, NextResponse } from "next/server";
21
import { redirect } from "next/navigation";
32
import { type Session, getGlobalConfig } from "./index";
43
import { cookies } from "next/headers";
54
import { ExchangeCodeForTokens } from "./lib/oauth";
65
import jwt from "jsonwebtoken";
76

8-
export const handleRedirect = async (req: NextRequest) => {
7+
export const handleRedirect = async (req: Request) => {
98
const config = getGlobalConfig();
109
const cookieStore = await cookies();
1110
const params = new URL(req.url).searchParams;
1211
const code = params.get("code");
1312

1413
if (!code) {
15-
return NextResponse.json(
14+
return Response.json(
1615
{ error: "Authorization code not found" },
1716
{ status: 400 },
1817
);
@@ -31,7 +30,7 @@ export const handleRedirect = async (req: NextRequest) => {
3130
error?: string;
3231
message?: string;
3332
};
34-
return NextResponse.json(
33+
return Response.json(
3534
{ error: error.message || "Failed to fetch user data" },
3635
{ status: 500 },
3736
);

src/server-actions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { NextRequest, NextResponse } from "next/server";
21
import { headers } from "next/headers";
32
import { cookies } from "next/headers";
43
import { redirect } from "next/navigation";
@@ -41,28 +40,28 @@ export const getSession = async (): Promise<Session | null> => {
4140
}
4241
};
4342

44-
export const signIn = async (redirectTo?: string): Promise<NextResponse> => {
43+
export const signIn = async (redirectTo?: string): Promise<Response> => {
4544
const config = getGlobalConfig();
4645
const session = await getSession();
4746
const cookieStore = await cookies();
4847
const headersList = await headers();
4948
const redirectUri = redirectTo ?? headersList.get("Referer") ?? "/";
5049
await cookieStore.set("REDIRECT_AFTER", redirectUri, { sameSite: "lax", httpOnly: true, secure: true });
5150
if (session) {
52-
return NextResponse.json({ message: "Already signed in" }, { status: 200 });
51+
return Response.json({ message: "Already signed in" }, { status: 200 });
5352
}
5453
const signInURL = `https://discord.com/api/oauth2/authorize?client_id=${config.clientId}&redirect_uri=${encodeURIComponent(config.redirectUri)}&response_type=code&scope=${config.scopes.join(" ")}`;
5554
return redirect(signInURL);
5655
};
5756

58-
export const signOut = async (): Promise<NextResponse> => {
57+
export const signOut = async (): Promise<Response> => {
5958
const cookieStore = await cookies();
6059
const token = cookieStore.get("AUTH_SESSION")?.value;
6160
if (!token) {
62-
return NextResponse.json({ message: "Not signed in" }, { status: 401 });
61+
return Response.json({ message: "Not signed in" }, { status: 401 });
6362
}
6463

6564
cookieStore.delete("AUTH_SESSION");
6665

67-
return NextResponse.json({ message: "Signed out successfully" }, { status: 200 });
66+
return Response.json({ message: "Signed out successfully" }, { status: 200 });
6867
};

types/redirect.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { NextRequest, NextResponse } from "next/server";
2-
31
export declare function handleRedirect(
4-
req: NextRequest,
5-
): Promise<NextResponse | void>;
2+
req: Request,
3+
): Promise<Response | void>;

types/server-actions.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { NextResponse } from "next/server";
21
import type { Session } from "./index";
32

43
export declare function getSession(): Promise<Session | null>;
54

6-
export declare function signIn(): Promise<NextResponse>;
5+
export declare function signIn(): Promise<Response>;
76

8-
export declare function signOut(): Promise<NextResponse>;
7+
export declare function signOut(): Promise<Response>;

0 commit comments

Comments
 (0)