Skip to content

Commit

Permalink
Update examples with new redirect helper
Browse files Browse the repository at this point in the history
  • Loading branch information
botv committed Jul 3, 2020
1 parent 35d96f8 commit 540c229
Show file tree
Hide file tree
Showing 26 changed files with 26 additions and 53 deletions.
5 changes: 1 addition & 4 deletions examples/auth0/pages/advanced/ssr-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export async function getServerSideProps({ req, res }) {
const session = await auth0.getSession(req)

if (!session || !session.user) {
res.writeHead(302, {
Location: '/api/login',
})
res.end()
res.redirect('/api/login')
return
}

Expand Down
3 changes: 1 addition & 2 deletions examples/cms-agilitycms/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function handler(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-agilitycms/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ export default async function handler(req, res) {
res.setPreviewData({})

// Redirect to the slug
res.writeHead(307, { Location: validationResp.slug })
res.end()
res.redirect(validationResp.slug)
}
3 changes: 1 addition & 2 deletions examples/cms-buttercms/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-buttercms/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-contentful/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
2 changes: 1 addition & 1 deletion examples/cms-contentful/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
// res.writeHead(307, { Location: `/posts/${post.slug}` })
// res.redirect(`/posts/${post.slug}`)
const url = `/posts/${post.slug}`
res.write(
`<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; url=${url}" />
Expand Down
3 changes: 1 addition & 2 deletions examples/cms-cosmic/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-cosmic/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-datocms/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-datocms/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-graphcms/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function handler(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-graphcms/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function handler(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-prismic/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-sanity/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-sanity/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-storyblok/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-storyblok/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post?.PostItem?.slug}` })
res.end()
res.redirect(`/posts/${post?.PostItem?.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-strapi/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-strapi/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-takeshape/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-takeshape/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` })
res.end()
res.redirect(`/posts/${post.slug}`)
}
3 changes: 1 addition & 2 deletions examples/cms-wordpress/pages/api/exit-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export default async function exit(_, res) {
res.clearPreviewData()

// Redirect the user back to the index page.
res.writeHead(307, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/cms-wordpress/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ export default async function preview(req, res) {

// Redirect to the path from the fetched post
// We don't redirect to `req.query.slug` as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug || post.databaseId}` })
res.end()
res.redirect(`/posts/${post.slug || post.databaseId}`)
}
3 changes: 1 addition & 2 deletions examples/with-magic/pages/api/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default async function logout(req, res) {
const session = await getSession(req)
await magic.users.logoutByIssuer(session.issuer)
removeTokenCookie(res)
res.writeHead(302, { Location: '/' })
res.end()
res.redirect('/')
}
3 changes: 1 addition & 2 deletions examples/with-passport/pages/api/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import { removeTokenCookie } from '../../lib/auth-cookies'

export default async function logout(req, res) {
removeTokenCookie(res)
res.writeHead(302, { Location: '/' })
res.end()
res.redirect('/')
}

0 comments on commit 540c229

Please sign in to comment.