Skip to content

Commit eec2088

Browse files
committed
refactor(SignInWithAuthjsButton): Use next auth signIn and remove @auth/core dep
1 parent e74b980 commit eec2088

File tree

4 files changed

+24
-66
lines changed

4 files changed

+24
-66
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
"typescript": "^5.7.3"
6868
},
6969
"nx": {},
70-
"dependencies": {
71-
"@auth/core": "^0.37.4"
72-
},
70+
"dependencies": {},
7371
"packageManager": "pnpm@9.12.3"
7472
}

pnpm-lock.yaml

Lines changed: 17 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/SignInWithAuthjsButton.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
import { createActionURL } from "@auth/core";
21
import { Button } from "@payloadcms/ui";
3-
import { headers } from "next/headers";
4-
import { redirect } from "next/navigation";
5-
import React from "react";
2+
import NextAuth from "next-auth";
63

74
/**
85
* A button that redirects the user to the Auth.js sign in page
96
*/
10-
export const SignInWithAuthjsButton = ({
11-
authjsBasePath,
12-
adminURL,
13-
}: {
14-
authjsBasePath: string;
15-
adminURL: string;
16-
}) => {
7+
export const SignInWithAuthjsButton = ({ authjsBasePath }: { authjsBasePath?: string }) => {
178
return (
189
<form
1910
style={{ display: "flex", justifyContent: "center" }}
2011
action={async () => {
2112
"use server";
2213

23-
const signInURL = createActionURL("signin", "https", await headers(), process.env, {
14+
const { signIn } = NextAuth({
2415
basePath: authjsBasePath,
16+
providers: [],
2517
});
26-
signInURL.searchParams.append("callbackUrl", adminURL);
2718

28-
redirect(signInURL.toString());
19+
await signIn();
2920
}}
3021
>
3122
<Button

src/payload/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export const authjsPlugin =
5555
{
5656
path: "payload-authjs/components#SignInWithAuthjsButton",
5757
serverProps: {
58-
authjsBasePath: pluginOptions.authjsConfig.basePath ?? "/api/auth",
59-
adminURL: config.routes?.admin ?? "/admin",
58+
authjsBasePath: pluginOptions.authjsConfig.basePath,
6059
},
6160
},
6261
]

0 commit comments

Comments
 (0)