feat: Enhance authentication handling by adding error logging and improving session checks in the API and ClaimDataModal component
This commit is contained in:
parent
0fbd9d5c38
commit
7482a4265e
4 changed files with 19 additions and 8 deletions
2
.github/workflows/docker-publish.yml
vendored
2
.github/workflows/docker-publish.yml
vendored
|
|
@ -92,7 +92,7 @@ jobs:
|
||||||
cache-from: type=gha,scope=${{ matrix.arch }}
|
cache-from: type=gha,scope=${{ matrix.arch }}
|
||||||
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
|
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
|
||||||
provenance: false
|
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
|
- name: Export digest
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ Set `WHISPER_CPP_BIN` in your `.env` to enable word-by-word highlighting.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/richardr1126/openreader.git
|
git clone https://github.com/richardr1126/openreader.git
|
||||||
cd OpenReader
|
cd openreader
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Install dependencies.
|
2. Install dependencies.
|
||||||
|
|
|
||||||
|
|
@ -105,9 +105,14 @@ async function scanLibraryRoot(root: string, rootIndex: number, limit: number):
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
// Auth check - require session
|
// Auth check - require session
|
||||||
const session = await auth?.api.getSession({ headers: req.headers });
|
try {
|
||||||
if (auth && !session?.user) {
|
const session = await auth?.api.getSession({ headers: req.headers });
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
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);
|
const url = new URL(req.url);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ export default function ClaimDataModal() {
|
||||||
progress: 0,
|
progress: 0,
|
||||||
});
|
});
|
||||||
const user = sessionData?.user;
|
const user = sessionData?.user;
|
||||||
|
const userId = user?.id;
|
||||||
|
|
||||||
const checkClaimableData = useCallback(async () => {
|
const checkClaimableData = useCallback(async () => {
|
||||||
setHasChecked(true);
|
setHasChecked(true);
|
||||||
|
|
@ -66,11 +67,16 @@ export default function ClaimDataModal() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only check once per session if user is logged in (non-anonymous)
|
// Reset per-user guard so account switches trigger a fresh check.
|
||||||
if (user && !user.isAnonymous && !hasChecked) {
|
setHasChecked(false);
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Only check once per authenticated user
|
||||||
|
if (userId && !user?.isAnonymous && !hasChecked) {
|
||||||
checkClaimableData();
|
checkClaimableData();
|
||||||
}
|
}
|
||||||
}, [user, hasChecked, checkClaimableData]);
|
}, [userId, user?.isAnonymous, hasChecked, checkClaimableData]);
|
||||||
|
|
||||||
const handleClaim = async () => {
|
const handleClaim = async () => {
|
||||||
setIsClaiming(true);
|
setIsClaiming(true);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue