forked from payloadcms/payload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(templates): seeding in website template moved to a separate route…
… so timeout can be customised (payloadcms#9327)
- Loading branch information
Showing
17 changed files
with
11,741 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import jwt from 'jsonwebtoken' | ||
import { createLocalReq, getPayload } from 'payload' | ||
import { seed } from '@/endpoints/seed' | ||
import config from '@payload-config' | ||
|
||
const payloadToken = 'payload-token' | ||
export const maxDuration = 60 // This function can run for a maximum of 60 seconds | ||
|
||
export async function POST( | ||
req: Request & { | ||
cookies: { | ||
get: (name: string) => { | ||
value: string | ||
} | ||
} | ||
}, | ||
): Promise<Response> { | ||
const payload = await getPayload({ config }) | ||
const token = req.cookies.get(payloadToken)?.value | ||
|
||
let user | ||
|
||
try { | ||
user = jwt.verify(token, payload.secret) | ||
} catch (error) { | ||
payload.logger.error('Error verifying token for live preview:', error) | ||
} | ||
|
||
if (!user) { | ||
return new Response('Action forbidden.', { status: 403 }) | ||
} | ||
|
||
try { | ||
// Create a Payload request object to pass to the Local API for transactions | ||
// At this point you should pass in a user, locale, and any other context you need for the Local API | ||
const payloadReq = await createLocalReq({ user }, payload) | ||
|
||
await seed({ payload, req: payloadReq }) | ||
|
||
return Response.json({ success: true }) | ||
} catch { | ||
return new Response('Error seeding data.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
templates/website/src/components/BeforeDashboard/SeedButton/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.seedButton { | ||
appearance: none; | ||
background: none; | ||
border: none; | ||
padding: 0; | ||
text-decoration: underline; | ||
|
||
&:hover { | ||
cursor: pointer; | ||
opacity: 0.85; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.