Skip to content

Missing Authorization flow for Cron jobs with Github Actions #5955

Answered by jsjoeio
paulphys asked this question in Ideas
Discussion options

You must be logged in to vote

You should post your answer here - that would have saved me some time 😂 Guess I'll post mine.

import { NextApiRequest, NextApiResponse } from "next"

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method === "POST") {
    try {
      const { authorization } = req.headers


      if (authorization === `Bearer ${process.env.API_SECRET_KEY}`) {
        res.status(200).json({ success: true })
      } else {
        res.status(401).json({ success: false })
      }
    } catch (err) {
      res.status(500).json({ statusCode: 500, message: err.message })
    }
  } else {
    res.setHeader("Allow", "POST")
    res.status(405).end("Method Not All…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@leerob
Comment options

@paulphys
Comment options

@jsjoeio
Comment options

Answer selected by leerob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants