@mikandev/next-discord-auth 1.0.2 → 1.0.3
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 +4 -0
- package/dist/server-actions.js +6 -1
- package/package.json +1 -1
package/dist/redirect.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
|
+
import { redirect } from "next/navigation";
|
|
2
3
|
import { getGlobalConfig } from "./index";
|
|
3
4
|
import { cookies } from "next/headers";
|
|
4
5
|
import { ExchangeCodeForTokens } from "./lib/oauth";
|
|
@@ -34,5 +35,8 @@ export const handleRedirect = async (req) => {
|
|
|
34
35
|
const token = jwt.sign(session, config.jwtSecret, {
|
|
35
36
|
expiresIn: response.expiresIn,
|
|
36
37
|
});
|
|
38
|
+
const redirectUri = cookieStore.get("REDIRECT_AFTER")?.value || "/";
|
|
37
39
|
cookieStore.set("AUTH_SESSION", token, { sameSite: "lax", httpOnly: true, secure: true });
|
|
40
|
+
cookieStore.delete("REDIRECT_AFTER");
|
|
41
|
+
return redirect(redirectUri);
|
|
38
42
|
};
|
package/dist/server-actions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import { headers } from "next/headers";
|
|
2
3
|
import { cookies } from "next/headers";
|
|
3
4
|
import { redirect } from "next/navigation";
|
|
4
5
|
import { getGlobalConfig } from "./index";
|
|
@@ -17,9 +18,13 @@ export const getSession = async () => {
|
|
|
17
18
|
return null;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
export const signIn = async () => {
|
|
21
|
+
export const signIn = async (redirectTo) => {
|
|
21
22
|
const config = getGlobalConfig();
|
|
22
23
|
const session = await getSession();
|
|
24
|
+
const cookieStore = await cookies();
|
|
25
|
+
const headersList = await headers();
|
|
26
|
+
const redirectUri = redirectTo ?? headersList.get("Referer") ?? "/";
|
|
27
|
+
await cookieStore.set("REDIRECT_AFTER", redirectUri, { sameSite: "lax", httpOnly: true, secure: true });
|
|
23
28
|
if (session) {
|
|
24
29
|
return NextResponse.json({ message: "Already signed in" }, { status: 200 });
|
|
25
30
|
}
|