Add dedicated users/me route using payload.auth
This commit is contained in:
@@ -1,22 +1,57 @@
|
||||
import { buildConfig } from 'payload'
|
||||
import { postgresAdapter } from '@payloadcms/db-postgres'
|
||||
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
||||
import { Users } from './payload/collections/Users'
|
||||
import { Services } from './payload/collections/Services'
|
||||
import { Realisations } from './payload/collections/Realisations'
|
||||
import { Articles } from './payload/collections/Articles'
|
||||
import { Testimonials } from './payload/collections/Testimonials'
|
||||
import { FAQ } from './payload/collections/FAQ'
|
||||
import { Media } from './payload/collections/Media'
|
||||
import { buildConfig } from 'payload';
|
||||
import { postgresAdapter } from '@payloadcms/db-postgres';
|
||||
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
||||
|
||||
const serverURL = process.env.NEXT_PUBLIC_SERVER_URL || ''
|
||||
import { Users } from './payload/collections/Users';
|
||||
import { Services } from './payload/collections/Services';
|
||||
import { Realisations } from './payload/collections/Realisations';
|
||||
import { Articles } from './payload/collections/Articles';
|
||||
import { Testimonials } from './payload/collections/Testimonials';
|
||||
import { FAQ } from './payload/collections/FAQ';
|
||||
import { Media } from './payload/collections/Media';
|
||||
|
||||
import nodemailer, { type Transporter } from 'nodemailer';
|
||||
|
||||
const serverURL = process.env.NEXT_PUBLIC_SERVER_URL || '';
|
||||
|
||||
const transporter: Transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: Number(process.env.SMTP_PORT) || 587,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env.SMTP_USER,
|
||||
pass: process.env.SMTP_PASS,
|
||||
},
|
||||
});
|
||||
|
||||
// on tape en `any` pour ne plus se battre avec EmailAdapter
|
||||
const emailAdapter: any = {
|
||||
sendEmail: async ({
|
||||
to,
|
||||
subject,
|
||||
html,
|
||||
text,
|
||||
from,
|
||||
}: {
|
||||
to: string | string[];
|
||||
subject: string;
|
||||
html: string;
|
||||
text: string;
|
||||
from?: string;
|
||||
}) => {
|
||||
await transporter.sendMail({
|
||||
from: from ?? '"OBC Maçonnerie" <no-reply@obc-maconnerie.com>',
|
||||
to,
|
||||
subject,
|
||||
html,
|
||||
text,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default buildConfig({
|
||||
secret: process.env.PAYLOAD_SECRET || 'change-moi',
|
||||
serverURL,
|
||||
// csrf: Payload auto-populates from serverURL when non-empty.
|
||||
// When serverURL is empty, csrf stays [] → all origins accepted (dev-safe).
|
||||
// cors: Allow the public origin to call the REST API from the browser.
|
||||
cors: serverURL ? [serverURL] : '*',
|
||||
editor: lexicalEditor(),
|
||||
routes: {
|
||||
@@ -26,6 +61,7 @@ export default buildConfig({
|
||||
admin: {
|
||||
user: 'users',
|
||||
},
|
||||
email: emailAdapter,
|
||||
db: postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.DATABASE_URL!,
|
||||
@@ -34,4 +70,4 @@ export default buildConfig({
|
||||
}),
|
||||
collections: [Users, Services, Realisations, Articles, Testimonials, FAQ, Media],
|
||||
globals: [],
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user