4

我有一个Link看起来像的标签<Link href='/api/twitter/generate-auth-link'>Login with Twitter</Link>

我已经创建pages/api/twitter/generate-auth-link.ts了如下所示:

import { NextApiResponse } from 'next'
import TwitterApi from 'twitter-api-v2'

import { TWITTER_CONFIG } from '../../../lib/config'
import { SERVER_URL } from '../../../utils/index'
import { NextIronRequest } from '../../../types/index'
import handler from '../../../server/api-route'

const generateAuthLink = async (
  req: NextIronRequest,
  res: NextApiResponse
) => {
  // Generate an authentication URL
  const { url, oauth_token, oauth_token_secret } = await new TwitterApi({
    appKey: TWITTER_CONFIG.consumerKey,
    appSecret: TWITTER_CONFIG.consumerSecret,
  }).generateAuthLink(`${SERVER_URL}api/twitter/get-verifier-token`, {linkMode:'authorize'})
  
  req.session.set(oauth_token, oauth_token_secret)
  await req.session.save()

  // redirect to the authentication URL
  res.redirect(url)
}

export default handler().get(generateAuthLink)

当我单击它时,它会引发以下错误:

1 of 1 unhandled error

Unhandled Runtime Error
Error: Failed to load script: /_next/static/chunks/pages/api/twitter/generate-auth-link.js

Call Stack
HTMLScriptElement.script.onerror
node_modules/next/dist/client/route-loader.js (83:51)

我如何解决它?

复制 → https://github.com/deadcoder0904/twitter-api-v2-3-legged-login-using-next-connect

4

0 回答 0