#starlight documentation with mysql auth

9 messages · Page 1 of 1 (latest)

deft garden
#

I'm trying to set up documentation for my recording studio using starlight, but I need auth to separate documentation for different groups of users with different access. All creds are in my mysql database.
I struggle sooo much.. chatgpt4 can't help me anymore 😦
I tried this template (starlight auth starter) with github auth implemented and rewrited it to use mysql2, and I tried to build my own from base starlight - no luck, there's always some wall that hold me down.

I did 20 approaches, most of them with nextra in nextjs, where I'm always arriving at the point where all login functionalities are working, and even contents of single documentation page are reacting to that, but menu/nav is showing all available docs for not logged users. I put the correct logic for that in right place but nextra is always falling back to reading menu items names from directory names instead - when there's not other configuration specified in config file.
Changing css display:hidden also couln't get to work :/

So I tried starlight, currently still working out the auth, cause the template is adjusted for oauth, I need just simple mysql credential for now (I consider hosting supabase or other tings for that) but it's quite painfull.

Just wanted to ask community, maybe someone have some idea, what would be best approach to implement functioning login for locally hosted documentation project/site (the creds are for now in mariadb database), with different access to particular docs for different class of users/public (which I already have stored in same database). Preferably decent looking from the box, with fast searchbar and edit functionalities for other "admin" users.

is it too much for a template to ask right?

#

starlight documentation with mysql auth

half pasture
#

Hey! So I could be wrong, and maybe someone else will jump in about this.

But this level of integration authentication into Starlight would require some custom components to display things correctly. And even then, I'm not 100% sure how to do it if I'm honest! Might be best asking in #starlight how easy it is to, say, rewire the sidebar to filter out links based on a condition - in this cased authenticated or with correct permissions.

As for authentication itself, Supabase or Clerk or whatever could be a good shout and will give you authentication. Or if you already have a db you could look at Lucia Auth which is highly recommended by many people in the Astro community! Lucia even has a guide specifically for Astro and a starter project!

Afaik this site sounds like a good amount of custom work you'd need to integrate authentication with what you need. For a simple "you can't see docs at all unless you're logged in" then the starter you linked should be a good starting point. However you're looking at full control over each page, and for that you'd be looking at custom Starlight components

deft garden
#

Thanks @half pasture for response

I'm coming from wild primitive php background, so I'm still thinking in server side rendering context. Still struggle to get, how these web frameworks exactly work on low level - abstraction became understandable for me only after grasping the mechanics.

If I understand correctly, for that application I need to use 'server' or 'hybrid' in astro configuration right?

I tried to gather some help but at this point, I have too many questions. #starlight for sure could be helpful but I'll try to hit it with more specific questions.

there's attached .zip with current state of things.

for now I'm trying to deal with

Cannot read properties of undefined (reading 'headers')
i18n/middleware.js:50:27

when I never intent to use any i18n in here

deft garden
#

Todays codebase, did some progress. Now I can login, and show correct version of docs for particular classes of users, but it works only on index.

Claude AI helped a lot.
Now I'm stuck making sidebar work as suppose for every doc site.
Cookie shows userRole as it should on index, but as soon as I move cursor to sidebar elements, it's changing to default "klient".
Which results in showing sidebar for klient.

half pasture
#

Hey! Sorry for the slow response on this. I'm glad you're making some progress! So we don't really want people just sending around .zip files in the discord for security reasons, are you able to transfer this to a repo or make a minimal reproduction in stackblitz?

deft garden
#

ofc it need .env

DB_HOST=<ip>
DB_PORT=<port>
DB_USER=<database_user>
DB_PASSWORD=<database_password>
DB_NAME=<database_name>
AUTH_SECRET=<some string>

The mysql query is in lib/auth.ts
ksywa = username
haslo = password
uprawnienia = userRole
realizatorzy = table of users able to login