@mikandev/next-discord-auth 0.0.6 → 0.0.7
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/index.js +10 -1
- package/dist/redirect.js +1 -1
- package/dist/server-actions.js +19 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
package/dist/redirect.js
CHANGED
|
@@ -24,7 +24,7 @@ export const handleRedirect = async (config, req) => {
|
|
|
24
24
|
user: {
|
|
25
25
|
id: userData.user.id,
|
|
26
26
|
name: `${userData.user.username}#${userData.user.discriminator}`,
|
|
27
|
-
email: userData.user.email
|
|
27
|
+
email: userData.user.email,
|
|
28
28
|
avatar: `https://cdn.discordapp.com/avatars/${userData.user.id}/${userData.user.avatar}.png`,
|
|
29
29
|
},
|
|
30
30
|
expires: new Date(Date.now() + response.expiresIn * 1000).toISOString(),
|
package/dist/server-actions.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
1
2
|
import jwt from "jsonwebtoken";
|
|
2
3
|
export const getSession = async (config, req) => {
|
|
3
4
|
const token = req.cookies.get("AUTH_SESSION")?.value;
|
|
@@ -5,11 +6,27 @@ export const getSession = async (config, req) => {
|
|
|
5
6
|
return null;
|
|
6
7
|
}
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
-
return decoded;
|
|
9
|
+
return jwt.verify(token, config.jwtSecret);
|
|
10
10
|
}
|
|
11
11
|
catch (error) {
|
|
12
12
|
console.error("Invalid token:", error);
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
export const signIn = async (config, req) => {
|
|
17
|
+
const session = await getSession(config, req);
|
|
18
|
+
if (session) {
|
|
19
|
+
return NextResponse.json({ message: "Already signed in" }, { status: 200 });
|
|
20
|
+
}
|
|
21
|
+
const signInURL = `https://discord.com/api/oauth2/authorize?client_id=${config.clientId}&redirect_uri=${encodeURIComponent(config.redirectUri)}&response_type=code&scope=${config.scopes.join(" ")}`;
|
|
22
|
+
return NextResponse.redirect(signInURL, 302);
|
|
23
|
+
};
|
|
24
|
+
export const signOut = async (config, req) => {
|
|
25
|
+
const session = await getSession(config, req);
|
|
26
|
+
if (!session) {
|
|
27
|
+
return NextResponse.json({ message: "Not signed in" }, { status: 401 });
|
|
28
|
+
}
|
|
29
|
+
const response = NextResponse.json({ message: "Signed out successfully" }, { status: 200 });
|
|
30
|
+
response.cookies.delete("AUTH_SESSION");
|
|
31
|
+
return response;
|
|
32
|
+
};
|