File tree Expand file tree Collapse file tree 6 files changed +83
-3
lines changed
dev/src/app/(payload)/admin Expand file tree Collapse file tree 6 files changed +83
-3
lines changed Original file line number Diff line number Diff line change 1-
1+ import { SignInWithAuthjsButton as SignInWithAuthjsButton_0 } from 'payload-authjs/components'
22
33export const importMap = {
4-
4+ "payload-authjs/components#SignInWithAuthjsButton" : SignInWithAuthjsButton_0
55}
Original file line number Diff line number Diff line change 1616 "types" : " ./dist/middleware.d.ts" ,
1717 "import" : " ./dist/middleware.js" ,
1818 "default" : " ./dist/middleware.js"
19+ },
20+ "./components" : {
21+ "types" : " ./dist/components/index.d.ts" ,
22+ "import" : " ./dist/components/index.js" ,
23+ "default" : " ./dist/components/index.js"
1924 }
2025 },
2126 "files" : [
8691 "typescript" : " ^5.6.2"
8792 },
8893 "nx" : {},
89- "dependencies" : {},
94+ "dependencies" : {
95+ "@auth/core" : " ^0.34.2"
96+ },
9097 "packageManager" :
" [email protected] " 9198}
Original file line number Diff line number Diff line change 1+ import { createActionURL } from "@auth/core" ;
2+ import { Button } from "@payloadcms/ui" ;
3+ import { headers } from "next/headers" ;
4+ import { redirect } from "next/navigation" ;
5+ import React from "react" ;
6+
7+ /**
8+ * A button that redirects the user to the Auth.js sign in page
9+ */
10+ export const SignInWithAuthjsButton = ( {
11+ authjsBasePath,
12+ adminURL,
13+ } : {
14+ authjsBasePath : string ;
15+ adminURL : string ;
16+ } ) => {
17+ return (
18+ < form
19+ style = { { display : "flex" , justifyContent : "center" } }
20+ action = { async ( ) => {
21+ "use server" ;
22+
23+ const signInURL = createActionURL (
24+ "signin" ,
25+ "https" ,
26+ headers ( ) ,
27+ process . env ,
28+ authjsBasePath ,
29+ ) ;
30+ signInURL . searchParams . append ( "callbackUrl" , adminURL ) ;
31+
32+ redirect ( signInURL . toString ( ) ) ;
33+ } }
34+ >
35+ < Button
36+ type = "submit"
37+ size = "large"
38+ buttonStyle = "secondary"
39+ icon = { < img src = "https://authjs.dev/img/logo-sm.png" alt = "Auth.js Logo" /> }
40+ iconPosition = "left"
41+ >
42+ Sign in with Auth.js
43+ </ Button >
44+ </ form >
45+ ) ;
46+ } ;
Original file line number Diff line number Diff line change 1+ export { SignInWithAuthjsButton } from "./SignInWithAuthjsButton" ;
Original file line number Diff line number Diff line change @@ -14,5 +14,28 @@ export const authjsPlugin =
1414 config . collections = config . collections ?? [ ] ;
1515 generateUsersCollection ( config . collections , pluginOptions ) ;
1616
17+ // Add custom components to admin
18+ config . admin = {
19+ ...config . admin ,
20+ components : {
21+ ...config . admin ?. components ,
22+ afterLogin : [
23+ ...( config . admin ?. components ?. afterLogin ?? [ ] ) ,
24+ // Add the SignInWithAuthjsButton component to the admin login page (only if the user collection is the admin user collection)
25+ ...( incomingConfig . admin ?. user === ( pluginOptions . userCollectionSlug ?? "users" )
26+ ? [
27+ {
28+ path : "payload-authjs/components#SignInWithAuthjsButton" ,
29+ serverProps : {
30+ authjsBasePath : pluginOptions . authjsConfig . basePath ?? "/api/auth" ,
31+ adminURL : config . routes ?. admin ?? "/admin" ,
32+ } ,
33+ } ,
34+ ]
35+ : [ ] ) ,
36+ ] ,
37+ } ,
38+ } ;
39+
1740 return config ;
1841 } ;
You can’t perform that action at this time.
0 commit comments