After logging in, `(0, next_auth_react__WEBPACK_IMPORTED_MODULE_3__.signIn)` appears to be undefined

I'm encountering an issue with my registration and login functionality. Registration works fine, but I receive an error when attempting to log in.

TypeError: (0 , next_auth_react__WEBPACK_IMPORTED_MODULE_3__.signIn) is not a function
    at $$ACTION_0 (webpack-internal:///(action-browser)/./actions/login.ts:28:70)
    at endpoint (webpack-internal:///(action-browser)/./node_modules/next/dist/build/webpack/loaders/next-flight-action-entry-loader.js?actions=%5B%5B%22C%3A%5C%5CUsers%5C%5CStudent%5C%5CDesktop%5C%5CnextAuth%5C%5Cauth-tutorial%5C%5Cactions%5C%5Clogin.ts%22%2C%5B%22login%22%2C%22%24%24ACTION_0%22%5D%5D%5D&__client_imported__=true!:9:17)

I even tried clearing my database and switching away from bcryptjs due to concerns about password encryption causing the problem.

Here is my 'auth.config.ts' file:

export default { 
    providers: [
        Credentials({
            async authorize(credentials){
                const validatedFields = LoginSchema.safeParse(credentials);

                if(validatedFields.success){
                    const {email, password} = validatedFields.data;

                    const user = await getUserByEmail(email);
                    if(!user || !user.password) return null;

                    // const passwordsMatch = await bcrypt.compare(
                    //     password,
                    //     user.password
                    // );

                    if(password) return user;
                
                }

                return null
            }
        })
    ] 
} satisfies NextAuthConfig

Next, let's look at the 'auth.ts' file:

import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
import authConfig from "./auth.config"
import { db } from "./lib/db"
 
 
export const { handlers: {GET, POST}, auth, signIn, signOut } = NextAuth({
  adapter: PrismaAdapter(db),
  session: { strategy: "jwt" },
  ...authConfig,
})

Finally, we have the 'login.ts' file:

export const login = async (values:z.infer<typeof LoginSchema>) => {
    const validatedFields = LoginSchema.safeParse(values)

    if(!validatedFields.success){
        return {error: "Invalid fields!"}

    }

    const {email, password} = validatedFields.data;

    try {
        await signIn("credentials",{
            email,
            password,
            redirectTo:  DEFAULT_LOGIN_REDIRECT
        })
    } catch (error) {
        console.log(error)
        return {error: "Something went wrong"}

    }
}

Answer №1

Ensure that in the server action (login.ts), you are correctly importing the signIn function from your auth file located at the project's root, and not mistakenly using 'next-auth/react'. It's easy to get led astray by auto-complete suggestions, so double check which package you are referencing.

import {signIn} from '@/auth'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS modules are not loading dependencies such as constants or controllers

While searching for the reason why a properly defined factory is not loading, I came across this question. This led me to contemplate on the concept of services being "defined in an angular module". Consider this example: angular.module('d3', ...

Updating cookies to utilize local storage in React and NextJS

I have a project that consists of 4 sources. In this particular project, my goal is to rewrite the cookie functionality to use local storage instead. I have successfully implemented this in the user source where the data is correctly saved in local storage ...

PHP echo does not transition to an Ajax success response

I'm facing a simple issue that I can't seem to resolve. After entering the username and password values and clicking the login button, PHP is not returning its value to Ajax success. Instead, it opens the webService.php page and echoes the result ...

Collapsible List Group Button Utilizing Bootstrap Remains Expanded

Looking for some guidance here. I am just starting out with Bootstrap and trying to learn from their website, but I'm having trouble figuring out how to make something collapsed. I found collapse.js, jquery.min.js, bootstrap.min.js, and transition.js ...

Generating a pdf Blob from an array and displaying it

I am encountering an issue with displaying my PDF file. The data is coming as a byte array, and this is how I currently have it set up: // data is initially String {0: % 1:P 2:D ...} const byteArray = _.map(data); // ["%", "P", "D", "F", "-", "1", ...

The issue with displaying inline block is that the divs are not appearing side by side on the

Two of my div elements, namely form-panel and data-panel, are currently not aligned on the same line. How can I use display:inline-block to align them in a single line? Please review the code provided below. I have already used display:inline-block on both ...

Trigger a popup alert when a Bootstrap select live search is clicked

<select class="selectpicker form-control" data-live-search="true" name = "name1" id ="id1"> <option>Option1</option> <option>Option1</option> <option>Option1</option> <option>Option1</option> ...

Don't forget to keep in mind the importance of the "Radio" value when you are submitting a form to yourself on

When dealing with a text input, you can remember the value entered by the user if the form is submitted to itself. This technique comes in handy for tools like a picture upload tool, where the user's input needs to be saved to avoid retyping after upl ...

Implement the anti-flickering script for Google Optimize in a NextJS/ReactJS environment

While working on a NextJS/ReactJS project, I am experimenting with setting up Google Optimize for some tests. One issue I have encountered is the flickering effect that occurs when Optimize changes visual elements during experiments. To address this probl ...

Store the information retrieved from an Ajax call regarding an artist on the page, ensuring that it is only saved once for that

I have been working on a single-page application that utilizes the Spotify REST API and JQuery to enable users to search for an artist and display their information on the page. However, I want to ensure that the app saves details about each artist only ...

Utilize JavaScript's $.Map() function in combination with Math.Max.Apply() to determine the tallest height possible

This code snippet demonstrates how to find the maximum height using jQuery. The $.fn. syntax is utilized to add this method as a jQuery Plugin. $.Map() creates a new array. Math.Max.Apply retrieves the max number from an array. $.fn.t ...

As I iterated over the Vehicles API data, I encountered an issue while trying to access specific Vehicle information. I received an error message stating "Cannot read property 'id' of undefined

Exploring the realms of Angular, with some experience in older versions, I find myself faced with a challenge involving two APIs - "/vehicles" and "/vehicle/{id}". The process involves fetching data from "/vehicles", iterating through it to match IDs, the ...

The Angular service "this" is altering the context of the window object

I must have made a mistake somewhere and I know I am overlooking something obvious. The aim is to create a service that provides basic authentication features such as login, logout, and checking if a user is logged in or not. Upon loading the page, I veri ...

What is the process of generating a VectorSource in OpenLayer 6.5 using a JavaScript object?

I'm in the process of developing a web application that utilizes OpenLayer 6.5. I need to dynamically mark certain locations without storing ".geojson" files on the server. Any suggestions on how I can achieve this? When attempting to create a Vector ...

JavaScript function occasionally experiences loading issues with CSS images

Have you ever encountered issues with a CSS background image failing to load? What might be the underlying cause? I've written some Javascript code that looks like this: function progressBar(file_id) { pbar = ($("<div />").attr('id&a ...

Controlling the display and status of DIV elements as radio button choices within a React application

I am seeking the React.js solution to a common challenge. I have five DIVs that will function as radio button options when clicked. This is what the HTML might look like: //List of option DIVs which act as radio buttons when clicked const options = () = ...

Leveraging the power of AWS API Gateway and Lambda for seamless image upload and download operations with Amazon

I have successfully created a lambda function to handle image uploads and downloads to s3. However, I am encountering difficulties with the proxy integration from the API Gateway. Despite reviewing the documentation and looking at this specific question ...

Tips for including descriptions on individual images within the jQuery PhotoStack gallery

Recently, I encountered a challenge. I am currently utilizing a PHP file for accessing images stored in a specific folder. Here is the snippet of my PHP code: <?php $location = 'albums'; $album_name = $_GET['album_name']; $files ...

Tips for binding the "name attribute" within an AngularJS loop

Is there a way to include the name attribute in the input tag using angular.js? I am able to add a question field with just a click, and similarly, an option input can also be added. However, the issue arises when trying to add a new option, as the name at ...

Looking to save a CSS element as a variable

I am working on improving the readability of my code in Protractor. My goal is to assign a CSS class to a variable and then use that variable within a click method. element.all(by.css("div[ng-click=\"setLocation('report_road')\"]")).cl ...