fix: reset password and env vars
This commit is contained in:
parent
db20a093ef
commit
e264e88b39
@ -1,7 +1,10 @@
|
||||
DATABASE_URI=postgres://postgres:<password>@127.0.0.1:5432/your-database-name
|
||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||
|
||||
DOMIAN_NAME=
|
||||
PORT=9889
|
||||
|
||||
DOMAIN_NAME=localhost:3000
|
||||
SERVER_URL=http://localhost:3000
|
||||
|
||||
SMTP_HOST=
|
||||
SMTP_USER=
|
||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@ -12,6 +12,7 @@
|
||||
"@headlessui/react": "^2.2.1",
|
||||
"@heroicons/react": "^2.2.0",
|
||||
"@hookform/resolvers": "^5.0.1",
|
||||
"@next/env": "^15.3.1",
|
||||
"@payloadcms/db-postgres": "3.31.0",
|
||||
"@payloadcms/next": "3.31.0",
|
||||
"@payloadcms/payload-cloud": "3.31.0",
|
||||
@ -3337,9 +3338,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@next/env": {
|
||||
"version": "15.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-15.2.3.tgz",
|
||||
"integrity": "sha512-a26KnbW9DFEUsSxAxKBORR/uD9THoYoKbkpFywMN/AFvboTt94b8+g/07T8J6ACsdLag8/PDU60ov4rPxRAixw==",
|
||||
"version": "15.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-15.3.1.tgz",
|
||||
"integrity": "sha512-cwK27QdzrMblHSn9DZRV+DQscHXRuJv6MydlJRpFSqJWZrTYMLzKDeyueJNN9MGd8NNiUKzDQADAf+dMLXX7YQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/eslint-plugin-next": {
|
||||
@ -12069,6 +12070,12 @@
|
||||
"react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc"
|
||||
}
|
||||
},
|
||||
"node_modules/next/node_modules/@next/env": {
|
||||
"version": "15.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-15.2.3.tgz",
|
||||
"integrity": "sha512-a26KnbW9DFEUsSxAxKBORR/uD9THoYoKbkpFywMN/AFvboTt94b8+g/07T8J6ACsdLag8/PDU60ov4rPxRAixw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/next/node_modules/postcss": {
|
||||
"version": "8.4.31",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
||||
|
@ -19,6 +19,7 @@
|
||||
"@headlessui/react": "^2.2.1",
|
||||
"@heroicons/react": "^2.2.0",
|
||||
"@hookform/resolvers": "^5.0.1",
|
||||
"@next/env": "^15.3.1",
|
||||
"@payloadcms/db-postgres": "3.31.0",
|
||||
"@payloadcms/next": "3.31.0",
|
||||
"@payloadcms/payload-cloud": "3.31.0",
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { admin } from '@/access/admin'
|
||||
import type { CollectionConfig } from 'payload'
|
||||
|
||||
const expirationInMinutes = parseInt(process.env.PASSWORD_RESET_EXPIRATION_IN_MINUTES || '30')
|
||||
const domain = process.env.DOMAIN_NAME || 'localhost:3000'
|
||||
import '../envConfig'
|
||||
|
||||
const expirationInMinutes = parseInt(process.env.PASSWORD_RESET_EXPIRATION_IN_MINUTES || '30', 10)
|
||||
const domain = process.env.DOMAIN_NAME || ''
|
||||
const serverUrl = process.env.SERVER_URL || ''
|
||||
|
||||
export const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
@ -13,31 +16,13 @@ export const Users: CollectionConfig = {
|
||||
admin: admin
|
||||
},
|
||||
auth: {
|
||||
// verify: {
|
||||
// generateEmailSubject: () => {
|
||||
// return `Verify Account for ${domain}`
|
||||
// },
|
||||
// generateEmailHTML: ({ req, token, user }) => {
|
||||
// const url = `https://${domain}/verify?token=${token}`
|
||||
// return `
|
||||
// <!doctype html>
|
||||
// <html>
|
||||
// <body>
|
||||
// <h1>Verify Account for ${domain}</h1>
|
||||
// <p>Hey ${user.email}, verify your email by clicking here: ${url}</p>
|
||||
// <p>If you have not recently been signed up for ${domain} then please ignore this email.</p>
|
||||
// </body>
|
||||
// </html>
|
||||
// `
|
||||
// },
|
||||
// },
|
||||
forgotPassword: {
|
||||
expiration: (60000 * expirationInMinutes),
|
||||
generateEmailSubject: () => {
|
||||
console.log({ domain, serverUrl, expirationInMinutes })
|
||||
return `Reset password request for ${domain}`
|
||||
},
|
||||
generateEmailHTML: (props) => {
|
||||
const resetPasswordURL = `https://${domain}/forgotPassword?token=${props?.token}`
|
||||
const resetPasswordURL = `${serverUrl}/forgotPassword?token=${props?.token}`
|
||||
|
||||
return `
|
||||
<!doctype html>
|
||||
@ -58,7 +43,6 @@ export const Users: CollectionConfig = {
|
||||
},
|
||||
fields: [
|
||||
// Email added by default
|
||||
// Add more fields as needed
|
||||
{
|
||||
name: 'role',
|
||||
type: 'select',
|
||||
|
4
src/envConfig.ts
Normal file
4
src/envConfig.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { loadEnvConfig } from '@next/env'
|
||||
|
||||
const projectDir = process.cwd()
|
||||
loadEnvConfig(projectDir)
|
@ -19,6 +19,8 @@ import { Pages } from './collections/Pages/Pages'
|
||||
import HoldRequests from './collections/Checkouts/HoldRequests'
|
||||
import Checkouts from './collections/Checkouts/Checkouts'
|
||||
|
||||
import './envConfig.ts'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
@ -30,8 +32,8 @@ export default buildConfig({
|
||||
},
|
||||
dateFormat: 'MM/dd/yyyy',
|
||||
},
|
||||
//cors: [process.env.DOMAIN_NAME || ''],
|
||||
//csrf: [process.env.DOMAIN_NAME || ''],
|
||||
cors: [process.env.SERVER_URL || ''],
|
||||
csrf: [process.env.SERVER_URL || ''],
|
||||
upload: {
|
||||
limits: {
|
||||
fileSize: 5000000, // in bytes
|
||||
|
@ -17,19 +17,16 @@ export const resetPassword = async (props: Props): Promise<boolean> => {
|
||||
const payload = await getPayload({ config: payloadConfig })
|
||||
|
||||
try {
|
||||
const result = await payload.resetPassword({
|
||||
await payload.resetPassword({
|
||||
collection: 'users',
|
||||
overrideAccess: false,
|
||||
overrideAccess: true,
|
||||
data: {
|
||||
password: password,
|
||||
token: token,
|
||||
}
|
||||
})
|
||||
console.log('result')
|
||||
console.log(result)
|
||||
return true
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user