C
C#8mo ago
hutoanhill

✅ .NET 8 Identity with SQLite

I am trying to implement .NET identity using a SQLite database. I've followed this tutorial which uses SQL Sever. Ive gotten up to 14:48 (run the app) where i tested the API using Swagger. I created an email and password that passed all the default requirements, but got a SQLite exception that a table didn't exist. assume at some point in this tutorial i did something that was supposed to set up the tables for SQL Server, but it does not work for SQLite. Here's what i did. I created a DataContext that extends IdentityDbContext with a constructer that passes a DbContextOptions<DataContext> to the base constructer i added these lines to my progam.cs
builder.Services.AddDbContext<DataContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("AuthConnection")));

builder.Services.AddAuthorization();

builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<DataContext>();
...
app.MapIdentityApi<IdentityUser>();
builder.Services.AddDbContext<DataContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("AuthConnection")));

builder.Services.AddAuthorization();

builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<DataContext>();
...
app.MapIdentityApi<IdentityUser>();
i added my connection string to appsettings.json:
"ConnectionStrings": {
"AuthConnection": "Data Source=auth.db;"
},
...
"ConnectionStrings": {
"AuthConnection": "Data Source=auth.db;"
},
...
i ran this on PowerShell in my project directory
dotnet ef migrations add Initial
dotnet ef migrations add Initial
I've got the following packages installed (related to my attempt to implement identity): - Microsoft.AspNetCore.Identiy.EntityFrameworCore - Microsoft.EntityFrameworkCore.Design - Microsoft.EntityFrameworkCore.Sqlite - Microsoft.EntityFrameworkCore.Tools This is my first foray into Data Contexts and Entity Framework. I am still not quite sure what ether are.
Patrick God
YouTube
.NET 8 Authentication with Identity in a Web API with Bearer Tokens...
🚀 Join the .NET Web Academy: https://learn.dotnetwebacademy.com 💖 Support me on Patreon for exclusive source code access: https://patreon.com/_PatrickGod 🚀 Get the .NET 8 Web Dev Jump-Start Course for FREE: https://dotnet8.patrickgod.com 🐦 Let's get social on Twitter/X: https://twitter.com/_PatrickGod 🔗 Let's connect on LinkedIn: https://www.li...
8 Replies
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP8mo ago
i see. testing...
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP8mo ago
worked! not sure how i missed that... Thanks!
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP8mo ago
should have. :/

Did you find this page helpful?