Creating a Real-Time Slack Clone Using Next.js, React, Tailwind, and Auth.js | Part 1/2 (2024)

Posted by


Welcome to this two-part tutorial on how to build a real-time Slack clone using Next.js, React, Tailwind CSS, and Auth.js. In this tutorial, we will cover setting up the project, creating the user authentication system, and building the main features of the Slack clone.

Part 1: Setting up the project and user authentication

Step 1: Set up your project

First, make sure you have Node.js installed on your machine. If you don’t have it installed, you can download it from the official Node.js website.

Next, create a new directory for your project and navigate into it using the terminal. Run the following command to initialize a new Next.js project:

npx create-next-app my-slack-clone

Once the project is created, navigate into the project directory:

cd my-slack-clone

Step 2: Install dependencies

Next, we need to install the necessary dependencies for our project. Run the following commands in the terminal:

npm install @chakra-ui/react @emotion/react @emotion/styled framer-motion
npm install @auth0/auth-js

These dependencies will be used for styling the project using Chakra UI, handling animations with Framer Motion, and implementing authentication with Auth.js.

Step 3: Set up Auth.js

To use Auth.js for authentication, you will need to sign up for an Auth0 account and create a new application. Once you have created your application, you will be provided with a domain and client ID.

Create a new file in the project root directory called auth.js and add the following code:

import createAuth0Client from "@auth0/auth-js";

const auth0 = await createAuth0Client({
  domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN,
  client_id: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID,
});

export default auth0;

Make sure to replace process.env.NEXT_PUBLIC_AUTH0_DOMAIN and process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID with your Auth0 domain and client ID.

Step 4: Create the authentication component

Next, create a new folder called components in the src directory of your project. Inside the components folder, create a new file called Auth.js and add the following code:

import { useEffect } from "react";
import auth0 from "../auth";

const Auth = () => {
  useEffect(() => {
    const initAuth = async () => {
      await auth0.init();
    };

    initAuth();
  }, []);

  return null;
};

export default Auth;

This component will initialize Auth0 when the component mounts. We will use this component to handle authentication throughout the project.

Step 5: Set up Tailwind CSS

To add Tailwind CSS to your project, run the following command in the terminal:

npm install tailwindcss postcss autoprefixer

Next, create a new file called tailwind.config.js in the project root directory and add the following code:

module.exports = {
  mode: "jit",
  purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
  darkMode: false,
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
};

Create a new file called styles/globals.css in the src directory of your project and import Tailwind CSS:

@tailwind base;
@tailwind components;
@tailwind utilities;

Import the global styles in the pages/_app.js file:

import '../styles/globals.css'

With these steps, you have set up the project and the user authentication system for the real-time Slack clone. In the next part of the tutorial, we will build the main features of the Slack clone, including creating channels, sending messages, and implementing real-time updates. Stay tuned for Part 2!

0 0 votes
Article Rating
42 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@codewithantonio
2 months ago

🔴CSS FIX (READ DURING 00:02:29 CHAPTER) 🔴

add "./src/features/**/*.{js,ts,jsx,tsx,mdx}" to tailwind.config.ts:

content: [

"./src/features/**/*.{js,ts,jsx,tsx,mdx}",
],

@fenixx0704
2 months ago

Hello Antonio! Thank you for your great content ! One question to you , can you also use rutube for uploading your video , cause in some Russian regions YouTube almost stopped working:

@2011kamp
2 months ago

After user button section when logged in and reload the page twice, user is logged out

@bobbydx_
2 months ago

anyone else also getting errors like "Cannot find module '@convex-dev/auth/nextjs'" ?

@Deus-lo-Vuilt
2 months ago

Thank you Antonio, it is appreciated that you do everything step by step and can see the process.

@alexawunor8853
2 months ago

How do you figure all this things out? 😅🤣

You're the standard man. Keep up the good work. 👌👍

@cubeunicorn4055
2 months ago

6:59:07

@hcp3128
2 months ago

Hey! What's your browser you are using?

@tmk2462
2 months ago

The GOAT, nothing else to say ! THANK YOU man ! Hi from Paris !!!!!!!!!!!!!!!

@BliitzPint
2 months ago

8:31:00 – Nope, actually not. Our RegEx does nothing here. n is a whitespace character that gets removed by trim(), so the RegEx is obsolete in this case.

@Fr4nz2K
2 months ago

Bro im here right now because my groupmate just said to the professor that we will create a application like Slack and he was ecstatic because most groups just decided to go with ecommerce app. Bro I thought I was cooked until I saw this 😂 So Antonio thank you.

@djangodeveloper07
2 months ago

getting module error at > 5 | import { ConvexAuthNextjsProvider } from "@convex-dev/auth/nextjs";

i installed
npm install @convex-dev/auth @auth/core

npx @convex-dev/auth

npx convex dev and npm run dev working fine, issue is triggering when i visit localhost,

anyone got the same issue ?

@palabrana6062
2 months ago

Hey, tell me if its responsive?

@alptekinocakdan
2 months ago

Hey Antonio, thank you for the tutorial. I know it is you policy but could you at least share globals.css and assets? It is so hard to fix problems. Within 2 weeks they changed nextjs version to 14.2.9 and globals.css interfering.

@dereksantossidi6850
2 months ago

Ate 5:54:31 he was like waking up, remember to exercise antonio and sleep well man :))).

PS: thanks so much for the course im in the middle of the amazon jungle and it's thansk to you that im practicing and learning typescript.

@marky9275
2 months ago

Yet another banger! Thank you Antonio, you da man! I would love to see you feature other frameworks in a video. Possibly Remix, Astro or Svelte?

@Harryclinton-wu4xs
2 months ago

The link is not woking

@muhammadusmanali3718
2 months ago

Great tutorial man

@yanDev
2 months ago

Hello, thanks for this project!
I love Convex I think it's an incredible tool and they're doing a great job developing it.

@pedrojorge2011
2 months ago

Only me with tailwind issues? It seems next, tailwind or shadcn ui update and some things change…