0.1.15 • Published 9 months ago
payload-auth0-plugin v0.1.15
payload-auth0-plugin
Extends payloadcms
with Auth0 integration
Current status
Install
yarn add payload-auth0-plugin
Get Started
server.ts
import { auth } from "express-openid-connect";
const config = {
authRequired: false,
idpLogout: true,
auth0Logout: true,
baseURL: process.env.REACT_APP_SERVER_BASE_URL,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
issuerBaseURL: process.env.AUTH0_DOMAIN,
secret: "<LONG_RANDOM_STRING>",
routes: {
login: process.env.REACT_APP_AUTH0_LOGIN_URL,
logout: process.env.REACT_APP_AUTH0_LOGOUT_URL,
callback: process.env.AUTH0_CALLBACK_URL,
},
};
app.use(auth(config));
REACT_APP env variables
REACT_APP_SERVER_BASE_URL=http://localhost:3000
REACT_APP_AUTH0_LOGIN_URL=/auth0/login # the one you set up in Auth0
REACT_APP_AUTH0_LOGOUT_URL=/auth0/logout # the one you set up in Auth0
AUTH0_CALLBACK_URL=/auth0/callback # the one you set up in Auth0
payload.config.ts
import Auth0Avatar from from "payload-auth0-plugin/dist/components/Auth0Avatar";
import { LoginButton } from "payload-auth0-plugin/dist/components";
export default buildConfig({
....
admin: {
avatar: Auth0Avatar,
logoutRoute: process.env.REACT_APP_AUTH0_LOGOUT_URL,
inactivityRoute: process.env.REACT_APP_INACTIVITY_URL,
components: {
afterLogin: [LoginButton()],
},
}
})
your-auth-collection.ts
import { Auth0Strategy } from "payload-auth0-plugin";
import { PictureField } from "payload-auth0-plugin/dist/components";
const MyAuthCollection: CollectionConfig = {
slug: "authCollection",
auth: {
strategies: [
{
name: Auth0Strategy.name,
strategy: (ctx) => {
return new Auth0Strategy(ctx, "authCollection");
},
},
],
},
fields: [
{
name: "picture",
type: "text",
admin: {
hidden: true,
condition: (data) => {
return data.picture;
},
},
},
{
name: "pictureVisual",
type: "ui",
admin: {
position: "sidebar",
condition: (_, siblingData) => {
return siblingData.picture;
},
components: {
Field: PictureField,
Cell: PictureField,
},
},
},
{
name: "sub",
type: "text",
admin: {
readOnly: true,
condition: (data) => {
return data.sub;
},
},
},
],
};
0.1.14
10 months ago
0.1.15
9 months ago
0.1.10
1 year ago
0.1.11
11 months ago
0.1.12
11 months ago
0.1.13
11 months ago
0.1.9
1 year ago
0.1.8
1 year ago
0.1.7
1 year ago
0.1.6
1 year ago
0.1.5
1 year ago
0.1.4
1 year ago
0.1.3
1 year ago
0.1.2
1 year ago
0.1.1
2 years ago
0.1.0
2 years ago
0.0.10
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.1
3 years ago