Skip to content

Commit

Permalink
fix: feide route
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Nov 17, 2024
1 parent d186ffb commit 095df5b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/app/api/auth/feide/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,27 @@ export async function GET(request: NextRequest) {
const cookieStore = await cookies();
const storedState = cookieStore.get('feide-state')?.value;
const codeVerifier = cookieStore.get('feide-code-verifier')?.value;
console.log('step 1');
console.log(code, state, storedState, codeVerifier);

if (!code || !state || !storedState || !codeVerifier) {
return NextResponse.json(null, { status: 400 });
}

console.log('step 2');
if (state !== storedState) {
return NextResponse.json(null, { status: 403 });
}

console.log('step 3');
const tokens = await validateFeideAuthorization(code, codeVerifier);
if (!tokens) {
return NextResponse.json(null, { status: 500 });
}
console.log('step 4');
const userInfoResponse = await fetch(env.FEIDE_USERINFO_ENDPOINT, {
headers: {
Authorization: `Bearer ${tokens.accessToken}`,
},
});
console.log('step 5');
const userInfo = await userInfoResponse.json();
console.log(userInfo);
return new Response(null, {
status: 500,
});

cookieStore.delete('feide-state');
cookieStore.delete('feide-code-verifier');
}
3 changes: 2 additions & 1 deletion src/components/auth/FeideButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { FeideLogo } from '@/components/assets/logos/FeideLogo';
import { Button } from '@/components/ui/Button';
import { Spinner } from '@/components/ui/Spinner';
import { api } from '@/lib/api/client';
import { useRouter } from 'next/navigation';

Expand All @@ -17,7 +18,7 @@ function FeideButton() {
className='w-full bg-[#3FACC2]/90 hover:bg-[#3FACC2] dark:bg-[#222832] hover:dark:bg-[#222832]/40'
onClick={() => signInMutation.mutate()}
>
<FeideLogo title='Feide' />
{signInMutation.isPending ? <Spinner /> : <FeideLogo title='Feide' />}
</Button>
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/routers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const authRouter = createRouter({
secure: env.NODE_ENV === 'production',
});

console.log(cookieStore.getAll());

return url.href;
}),
});
Expand Down
11 changes: 10 additions & 1 deletion src/server/auth/feide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ async function createFeideAuthorization() {
const codeVerifier = generateCodeVerifier();
const url = await feideOAuthClient.createAuthorizationURL({
state,
scopes: ['openid', 'profile', 'email'],
scopes: [
'openid',
'profile',
'userinfo-name',
'userid-feide',
'email',
'userinfo-mobile',
'userinfo-photo',
'userinfo-birthdate',
],
codeVerifier,
});
return {
Expand Down

0 comments on commit 095df5b

Please sign in to comment.