Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
753 views
in Technique[技术] by (71.8m points)

next.js - Cannot get a response from PostgreSQL server

I freely admit that I am completely new to next-auth and the documentation for Credentials is understandably very light. I have got the email link process to work perfectly and will be moving users across top this.

Unfortunately, I have a lot of user data that will require credentials to login and, after spending a few days getting nowhere, I just want to get some idea of what I am doing wrong! This is my [...nextauth].js file:

import NextAuth from "next-auth";
import Providers from "next-auth/providers";
import axios from 'axios'

const options = {
  providers: [
    Providers.Email({
      server: {
        host: process.env.EMAIL_SERVER_HOST,
        port: process.env.EMAIL_SERVER_PORT,
        auth: {
          user: process.env.EMAIL_SERVER_USER,
          pass: process.env.EMAIL_SERVER_PASSWORD
        }
      },
      from: process.env.EMAIL_FROM
    }),
    Providers.Credentials({
      credentials: {
        mem_num: { label: "Membership Number", type: "text", placeholder: "12345" },
        password: { label: "Password", type: "text" }
      },
      authorize: async (credentials) => {
        console.log("credentials: ", credentials)
        try {
          const data = {
            mem_num: credentials.mem_num,
            password: credentials.password
          }
          const user = await login(data)
          if (user) {
            console.log('user:', user)
            return user
          }
        } catch (error) {
          if (error.response) {
            console.log(error.response)
            Promise.reject(new Error('Invalid Number and Password combination'))
          }
        }
      }
    })
  ],
  site: process.env.NEXTAUTH_URL || "http://localhost:3000",
  database: process.env.DATABASE_URL,
  session: {
    // Use JSON Web Tokens for session instead of database sessions.
    // This option can be used with or without a database for users/accounts.
    // Note: `jwt` is automatically set to `true` if no database is specified.
    jwt: true,
  },
}

const login = async data => {
  var config = {
      headers: {
          'Content-Type': "application/json; charset=utf-8",
          'corsOrigin': '*',
          "Access-Control-Allow-Origin": "*"
      }
  };
  const url = process.env.DATABASE_URL;
  const result = await axios.post(url, data, config);
  console.log('result', result);
  return result;
};

export default (req, res) => NextAuth(req, res, options);
question from:https://stackoverflow.com/questions/66050478/cannot-get-a-response-from-postgresql-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...