rforssen.net – *Practical guide on how to implement authentication correctly*
Mixed public content + authenticated personalization
This is used when an application should load normally for anyone, but behave differently based on login state and role.
Examples:
You already have the correct backend foundation:
| Endpoint | Description |
|---|---|
| /auth/login/google | Start login |
| /auth/login/google/callback | Finish login |
| /auth/me | Check login + get user info |
| /auth/logout | End session |
If NOT authenticated:
{
"authenticated": false
}
If authenticated:
{
"authenticated": true,
"user": {
"email": "...",
"name": "...",
"sub": "google-id"
},
"role": "me | family | public"
}
Every page using in-app authentication follows this pattern:
fetchAuth() → calls /auth/merenderAuthBadge() updates UI
Your media app already implements this extremely well
(using fetchAuth(), initAuth(),
BroadcastChannel, popup login, etc.).
This is your platform standard.
A mixed page normally behaves like this:
Filtering works with classes and logic like:
// If not logged in
hideElementsWithClass("onlyMe");
hideElementsWithClass("familyOnly");
// If Roland
show everything
setRole("me");
// If Family
show public + family
Even if UI hides features, the backend always decides access.
| Operation | Auth Requirement |
|---|---|
| Delete video | me only |
| Trigger FFmpeg job | me only |
| View private family media | me + family |
| View public content | anyone |
Ensure Flask session configuration:
SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SAMESITE = "Lax"
Only approve whitelisted domains
when handling:
?redirect=
/auth/me called on loadHard gate – block all access unless authenticated
Use this when nothing should be visible unless the user is authenticated. Not even the UI. No partial access. No leaks.
Perfect for:
This means the protected application never sees anonymous traffic.
If app wants to know who logged in:
X-Auth-User X-Auth-Email X-Auth-Verified
App may:
| Need | Use |
|---|---|
| Public + private experience | In-App Auth |
| Roles + personalization | In-App Auth |
| Family or guest usability | In-App Auth |
| Admin tools | Edge Auth |
| phpMyAdmin | Edge Auth |
| Cluster dashboards | Edge Auth |
| Any “dangerous” system | Edge Auth |