feat: Enhance authentication handling by adding error logging and improving session checks in the API and ClaimDataModal component

This commit is contained in:
Richard R 2026-02-19 02:13:43 -07:00
parent 0fbd9d5c38
commit 7482a4265e
4 changed files with 19 additions and 8 deletions

View file

@ -92,7 +92,7 @@ jobs:
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
provenance: false
outputs: type=image,name=${{ env.REGISTRY }}/${{ needs.prepare.outputs.image_name }},push-by-digest=true,name-canonical=true,push=true
outputs: type=image,name=${{ env.REGISTRY }}/${{ needs.prepare.outputs.image_name }},${{ env.REGISTRY }}/${{ needs.prepare.outputs.legacy_image_name }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |

View file

@ -63,7 +63,7 @@ Set `WHISPER_CPP_BIN` in your `.env` to enable word-by-word highlighting.
```bash
git clone https://github.com/richardr1126/openreader.git
cd OpenReader
cd openreader
```
2. Install dependencies.

View file

@ -105,9 +105,14 @@ async function scanLibraryRoot(root: string, rootIndex: number, limit: number):
export async function GET(req: NextRequest) {
// Auth check - require session
const session = await auth?.api.getSession({ headers: req.headers });
if (auth && !session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
try {
const session = await auth?.api.getSession({ headers: req.headers });
if (auth && !session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
} catch (error) {
console.error('Error checking auth:', error);
return NextResponse.json({ error: 'Error checking auth' }, { status: 500 });
}
const url = new URL(req.url);

View file

@ -43,6 +43,7 @@ export default function ClaimDataModal() {
progress: 0,
});
const user = sessionData?.user;
const userId = user?.id;
const checkClaimableData = useCallback(async () => {
setHasChecked(true);
@ -66,11 +67,16 @@ export default function ClaimDataModal() {
}, []);
useEffect(() => {
// Only check once per session if user is logged in (non-anonymous)
if (user && !user.isAnonymous && !hasChecked) {
// Reset per-user guard so account switches trigger a fresh check.
setHasChecked(false);
}, [userId]);
useEffect(() => {
// Only check once per authenticated user
if (userId && !user?.isAnonymous && !hasChecked) {
checkClaimableData();
}
}, [user, hasChecked, checkClaimableData]);
}, [userId, user?.isAnonymous, hasChecked, checkClaimableData]);
const handleClaim = async () => {
setIsClaiming(true);