Based on some tutorials, and other knowledge I've gained from the Qwik Discord and another project using Cloudflare D1 (SQLite)
This is the base of the actual authentication logic
Uses Prisma and NextJS
I opted for Drizzle as it should be more lightweight/performant and similar DX
Not Yet Implemented in this app
- Qwik/Qwik-City
- Drizzle ORM
- SQLite3 (LibSQL)
- @node-rs/argon2
- @oslojs/crypto
- @oslojs/encoding
plugin@db.ts, db/index.ts
- initializes the DB as a singleton (borrowed from what someone shared on Discord, and I used this style in my other app)
- includes auth functions from the first linked guide
- Note: for testing, it's using 15/30 second sessions! Guide uses 15/30 days
- simple routes for auth flow
- uses
routeAction$()s to submit from Form components
- shows different links based on if authenticated
- borrowed/modified from the Qwik starter
- (install modules with
pnpm installornpm install, etc) - Create a
local.dbfile in the root directory - Create a
.envfile in the root directory with one line:DB_FILE_NAME="file:local.db" - run
pnpm exec drizzle-kit push(ornpx drizzle-kit push, etc)
- this creates the db tables in
local.dbbased off of the schemas/relations
pnpm run devto start the app in dev mode
- Surely needs some cleanup and some styling but it's in a working state for basic auth and protected routes
- Try going to
/profileand you shoud be redirected to/loginsince it is a protected route - Go to
/registerand register a new user (no validation implemented yet) - Go to
/loginand log in with that new user
- can use EITHER userName OR email, along with password
- Should be redirected to
/profileafter login!
- Log out using the
Log Outbutton and now you no longer can access/profileprotected route
- tried first setting up onPost for the form handlers and logout link but had issues, so switched to
routeAction$()s and aserver$()fn for logout button - tried moving the
logoutserver$()function to another file but saw some Qwik import errors and wasn't able to log out
- Not sure on this, maybe it would help to wrap the auth helper functions with
server$()?