After logging in with next auth in a next.js app directory, Tailwind CSS fails to load

My updated authentication options are as follows:

import CredentialsProvider from "next-auth/providers/credentials";
import { type AuthOptions } from "next-auth";

export const nextAuthOptions: AuthOptions = {
  providers: [
    CredentialsProvider({
    name: "Credentials",

    credentials: {
      username: { label: "Username", type: "text", placeholder: "jsmith" },
      password: { label: "Password", type: "password" },
   },
    async authorize(credentials: any, req): Promise<any> {
    const user = {
      name: credentials.email,
      id: Math.random(),
      email: credentials.email,
      password: credentials.PhoneOtp,
    };

    if (user) {
      return user;
    } else {
      return null;
    }
  },
   }),
 ],
 callbacks: {
   async signIn() {
  return true;
   },
   async jwt({ token, user, trigger, session }: any) {
     if (trigger === "update") {
      return { ...token, ...session.user };
    }

    return { ...token, ...user };
  } ,

  async session({ session, token }: any) {
  session.user = token;
  return session;
},
},
  session: {
  maxAge: 60 * 60, // 1 hour in seconds
  strategy: "jwt",
},
 pages: {
  signIn: "/signin", // Custom sign-in screen URL
},

};

This is the middleware file for Next.js:

export { default } from "next-auth/middleware";
export const config = {
 matcher: ["/posts", "/home"],
 };

In a client component, I perform a sign-in like this:

    await signIn("credentials", {
      email: userInfo.email,
      password: watch("Phone_otp"),
      redirect: true,
      // accessToken: JSON.stringify(data.response),
      callbackUrl: "/home",
    })
      .then(() => {
        dispatch({
          type: reducerActions.HIDE_LOADER,
        });
        router.push("/home");
        console.log("then executed >");
        // redirect("/home");
      })
      .catch((err: any) => {
        dispatch({
          type: reducerActions.HIDE_LOADER,
        });
        console.log(" signin err > ", err);
      });

However, after signing in, the Tailwind CSS does not load even after performing a hard reload. Sometimes, when accessing an unauthorized page and returning, the CSS loads properly. I am unsure why this behavior is occurring in my Next.js app.

Answer №1

Dealing with CSS loading issues in my nextjs, nextauth, and app router setup was a head-scratcher. After some investigation, I discovered that the culprit was actually a misconfiguration in my tailwind.config.js.

The root of the problem stemmed from me starting the nextjs project without the src directory initially. Later on, I decided to add it in, but failed to update the paths in the tailwind.config.js, which wreaked havoc on the styling.

Here's what it looked like before:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
    './app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  ...
}

And here's the corrected version:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
    './src/components/**/*.{js,ts,jsx,tsx,mdx}',
    './src/app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  ...
}

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

Incorporate Functionality into AngularJS Controller

Although I have experience with other MVC Frameworks, I am new to AngularJS and facing an issue. My controller is named "Projects" and the route is /projects. However, I want to be able to navigate to /projects/java where a new page template/view will be d ...

Selecting options with a click of a button in Template-Driven Forms

Whenever the page loads, I always notice that the last radio button is automatically checked. I believe it has something to do with the Id attribute, but I'm struggling to find a solution. countryArray countryA = [{name : "Finland"}, {name : "china" ...

Prevent anchor tags from halting click propagation

After some experimentation, I discovered that a tags can interrupt event propagation in the DOM. For example, clicking on the red button should log text, but if you click where they overlap, only the link behavior occurs. Is there a way to ensure the event ...

Different Types of Forms on a Single Webpage Using AJAX

I'm struggling to get multiple forms to work on the same page. No matter what I try, it always submits the first form. The goal is to identify each form uniquely so that only the specific one is submitted. The current code below achieves this but alw ...

Is it possible for jcarousel to interact with a database as well?

Hey there, I've been searching everywhere but couldn't find any information on how to make jcarousel work with a database. That's why I'm reaching out here for some help. I have a page where I'm using jcarousel. css js Currently ...

The fixed div is always positioned in the top corner

My webpage has a 'Book Now' button that remains at the top of the viewport with a 10px gap. However, due to the parent element having a height of 100%, the button scrolls out of view once the viewport surpasses that height. To see an example, cli ...

The bundle injected by Webpack-dev-server into the HTML page fails to display any rendered content

Whenever I execute webpack-dev-server (Command: "webpack-dev-server --mode development --open --progress --hot"), the bundle gets injected into the html page, but nothing actually appears on the screen. This is how my Webpack.config.js file looks like: v ...

Displaying a set through an express server cookie for the client to see

New to using Express and encountering issues with sending cookies. Created a basic express app that is supposed to set a cookie in the browser. Here's the server setup: const express = require('express'); const cookieParser = require(' ...

The z-index property in jQuery dialog does not seem to function properly when used within an

When using bootstrap with jQuery dialog, I encountered a strange issue. If the z-index of the dialog is set to 1 or higher in a standalone script, everything works fine. However, when the same script is called inside an iframe, the dialog ends up appearing ...

Tips for dynamically populating an HTML table with data from a JSON array using JQuery

I have generated an HTML table <table id="top_five_table"> <tr> <td> </th> <th>URL</th> <th width="90">Total Hits</th> <th width="380">Percentage of all Hits</th> </tr> <tr> ...

Displaying Date in Angular 2 Application with Proper Formatting

I'm currently working on formatting the date pipe in my Angular application to display correctly when used within an input template. Originally, without the date formatting, my code looked like this: <input class="app-input" [readonly]="!hasAdminA ...

Searching for a value within an array of objects using JavaScript: The ultimate guide

Similar Question: Locate specific object by id within a JavaScript objects array What is the best way to determine if a value exists in a given JavaScript array? For instance: var arr = [ {id: 1, color: 'blue'}, {id: 2, colo ...

Choose all elements that share a common class

I want to create a hover effect that highlights all elements on a page with the same class. This is the code I currently have: $(document).ready(function () { $('p.myclass').mouseover(function () { $(this).addClass('hover'); }); $( ...

There seems to be an issue with the Ajax call as it is returning a null

The situation at hand is this: Whenever I initiate an ajax call with the provided script, it always triggers the error exception instead of a success. The XML output seems to be correctly formatted with the appropriate mime type and character set. Since t ...

Loop through an array of buttons using an event listener

My HTML and Javascript code currently have the functionality to show/hide a row of 3 images upon button click. However, I need this feature to work for two additional rows similar to this one. I believe it involves looping through an array of buttons, but ...

What is the most effective method for implementing a background repeated image in Foundation 4 framework?

Currently, I am utilizing the foundation4 framework for my website. In order to achieve a repeating tiled background, I have crafted a custom CSS file and included the following code snippet: body { background: url(img/floorboardsbg.jpg) repeat; } Whi ...

How can you individually set an on change event for each dynamically appended input?

I am attempting to create an on change event (using jQuery) for an appended html template containing inputs. Here is what I have so far: HTML <div class="scroller" id='videoInfoColumn' style="height: 600px; overflow-x: hidden;t ...

Executing JavaScript function by clicking on <img>

I've been developing a website similar to YouTube, and I'm facing difficulties with the Like/Dislike feature for comments. Currently, I have implemented it in the following way: when a user clicks on an image (thumbsUp.png or thumbsDown.png), a ...

Attempting to send an AJAX request to a different server (not functioning with the provided example)

UPDATE - Issue Resolved. Many thanks to everyone who provided input. After conducting extensive research, I discovered that instead of CORS, I needed to focus on JSONP all along. I have read several tutorials and believe I now have a good grasp of the con ...

Integrate stylish checkbox design into a form in Rails

I discovered some beautiful css styles for checkboxes that I would like to use instead of the regular ones. You can find these styles here: . Could someone guide me on how to implement this change? This is the code snippet from the form: <div class=" ...