,

Efficient ASP.NET Core Vite Vue SPA Tailwind Template featuring Identity Authentication

Posted by

Introduction:
In this tutorial, we will be creating a Productive ASP.NET Core Vite Vue SPA Tailwind Template with Identity Auth. This template will help you jumpstart your web development projects by providing a pre-configured setup with ASP.NET Core, Vite, Vue, Tailwind CSS, and Identity authentication already integrated.

Prerequisites:
Before we get started, make sure you have the following installed on your machine:

  • .NET Core SDK
  • Node.js
  • Visual Studio Code (optional)
  • Git

Creating a New ASP.NET Core Project:
First, let’s create a new ASP.NET Core project using the following .NET CLI command:

dotnet new webapi -n my-project
cd my-project

Next, open the project in your code editor and install the necessary packages:

dotnet add package Microsoft.AspNetCore.SpaServices.Extensions

Setting up Vite and Vue:
To integrate Vite and Vue into our project, we will use the Vite DotNet template. Run the following commands to install the template and create a new project:

dotnet new -i Vite.DotNet.Templates::1.1.5
dotnet new vitevue -na MyProject
cd MyProject

Installing Tailwind CSS:
We will be using Tailwind CSS for styling our application. Install Tailwind CSS by running the following commands:

npm install -D tailwindcss@latest postcss autoprefixer
npx tailwindcss init -p

Now, update your tailwind.config.js file to include the necessary configurations:

module.exports = {
  purge: ['./src/**/*.html', './src/**/*.vue'],
  darkMode: false,
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

Creating Identity Authentication:
To add Identity authentication to our project, run the following commands:

dotnet new package Microsoft.AspNetCore.Identity.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet ef migrations add InitialCreate
dotnet ef database update

Update the appsettings.json file with your database connection string:

"ConnectionStrings": {
  "DefaultConnection": "Server=(localdb)mssqllocaldb;Database=MyDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"
}

Lastly, add the necessary services to the Startup.cs file:

services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services.AddDefaultIdentity<IdentityUser>(options =>
    options.SignIn.RequireConfirmedAccount = true)
    .AddEntityFrameworkStores<ApplicationDbContext>();

Conclusion:
Congratulations! You have successfully created a Productive ASP.NET Core Vite Vue SPA Tailwind Template with Identity Auth. This template will help you quickly kick off your web development projects and save you time on setting up authentication and styling. Feel free to customize the template further to suit your project needs. Happy coding!