@mikandev/next-discord-auth 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/redirect.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
1
|
import { redirect } from "next/navigation";
|
|
3
2
|
import { getGlobalConfig } from "./index";
|
|
4
3
|
import { cookies } from "next/headers";
|
|
@@ -10,7 +9,7 @@ export const handleRedirect = async (req) => {
|
|
|
10
9
|
const params = new URL(req.url).searchParams;
|
|
11
10
|
const code = params.get("code");
|
|
12
11
|
if (!code) {
|
|
13
|
-
return
|
|
12
|
+
return Response.json({ error: "Authorization code not found" }, { status: 400 });
|
|
14
13
|
}
|
|
15
14
|
const response = await ExchangeCodeForTokens(config, code);
|
|
16
15
|
const sessionData = await fetch("https://discord.com/api/users/@me", {
|
|
@@ -20,7 +19,7 @@ export const handleRedirect = async (req) => {
|
|
|
20
19
|
});
|
|
21
20
|
if (!sessionData.ok) {
|
|
22
21
|
const error = (await sessionData.json());
|
|
23
|
-
return
|
|
22
|
+
return Response.json({ error: error.message || "Failed to fetch user data" }, { status: 500 });
|
|
24
23
|
}
|
|
25
24
|
const userData = (await sessionData.json());
|
|
26
25
|
const session = {
|
package/dist/server-actions.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from "next/server";
|
|
2
1
|
import { headers } from "next/headers";
|
|
3
2
|
import { cookies } from "next/headers";
|
|
4
3
|
import { redirect } from "next/navigation";
|
|
@@ -49,7 +48,7 @@ export const signIn = async (redirectTo) => {
|
|
|
49
48
|
const redirectUri = redirectTo ?? headersList.get("Referer") ?? "/";
|
|
50
49
|
await cookieStore.set("REDIRECT_AFTER", redirectUri, { sameSite: "lax", httpOnly: true, secure: true });
|
|
51
50
|
if (session) {
|
|
52
|
-
return
|
|
51
|
+
return Response.json({ message: "Already signed in" }, { status: 200 });
|
|
53
52
|
}
|
|
54
53
|
const signInURL = `https://discord.com/api/oauth2/authorize?client_id=${config.clientId}&redirect_uri=${encodeURIComponent(config.redirectUri)}&response_type=code&scope=${config.scopes.join(" ")}`;
|
|
55
54
|
return redirect(signInURL);
|
|
@@ -58,8 +57,8 @@ export const signOut = async () => {
|
|
|
58
57
|
const cookieStore = await cookies();
|
|
59
58
|
const token = cookieStore.get("AUTH_SESSION")?.value;
|
|
60
59
|
if (!token) {
|
|
61
|
-
return
|
|
60
|
+
return Response.json({ message: "Not signed in" }, { status: 401 });
|
|
62
61
|
}
|
|
63
62
|
cookieStore.delete("AUTH_SESSION");
|
|
64
|
-
return
|
|
63
|
+
return Response.json({ message: "Signed out successfully" }, { status: 200 });
|
|
65
64
|
};
|
package/dist/types/redirect.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { NextResponse } from "next/server";
|
|
2
1
|
import type { Session } from "./index";
|
|
3
2
|
|
|
4
3
|
export declare function getSession(): Promise<Session | null>;
|
|
5
4
|
|
|
6
|
-
export declare function signIn(): Promise<
|
|
5
|
+
export declare function signIn(): Promise<Response>;
|
|
7
6
|
|
|
8
|
-
export declare function signOut(): Promise<
|
|
7
|
+
export declare function signOut(): Promise<Response>;
|