Skip to content

Commit 86fe34e

Browse files
it's working bro.. 🥦
1 parent 4286cda commit 86fe34e

File tree

9 files changed

+73
-118
lines changed

9 files changed

+73
-118
lines changed

src/app.d.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// See https://svelte.dev/docs/kit/types#app.d.ts
2-
// for information about these interfaces
31
declare global {
42
namespace App {
5-
// interface Error {}
6-
// interface Locals {}
7-
// interface PageData {}
8-
// interface PageState {}
9-
// interface Platform {}
3+
interface Locals {
4+
auth(): Promise<import('@auth/core').Session | null>;
5+
}
6+
interface PageData {
7+
session: import('@auth/core').Session | null;
8+
}
109
}
11-
}
12-
13-
export {};
10+
}
11+
12+
export {};

src/hooks.server.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
// hooks.server.ts
2-
import { sequence } from '@sveltejs/kit/hooks';
31
import { handle as authHandle } from '../src/auth/auth';
42

5-
// If you need to add custom middleware
6-
//@ts-ignore
7-
const customHandle = async ({ event, resolve }) => {
8-
// Add any custom middleware logic here before auth
9-
return resolve(event);
10-
};
3+
export const handle = async ({ event, resolve }) => {
4+
// Use SvelteKitAuth's handle to process authentication
5+
const response = await authHandle({ event, resolve });
6+
7+
// If you want to add additional middleware logic, you can do so here
118

12-
// Export the sequence of handlers
13-
export const handle = sequence(customHandle, authHandle);
9+
return response;
10+
};

src/lib/components/ui/WavyBackground/WavyBackground.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
};
3333
3434
const init = () => {
35-
console.log(canvasRef);
35+
//console.log(canvasRef);
3636
canvas = canvasRef;
3737
ctx = canvas.getContext('2d');
38-
console.log('ctx', ctx);
38+
//console.log('ctx', ctx);
3939
w = ctx.canvas.width = window.innerWidth;
4040
h = ctx.canvas.height = window.innerHeight;
4141
ctx.filter = `blur(${blur}px)`;
File renamed without changes.

src/routes/profile/+page.server.ts

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,42 @@ import { redirect } from '@sveltejs/kit';
22
import type { PageServerLoad } from './$types';
33

44
export const prerender = 'auto';
5-
6-
export const load: PageServerLoad = async (event) => {
7-
const session = await event.locals.auth();
8-
9-
if (!session?.user) {
10-
throw redirect(303, '/login');
11-
}
12-
13-
const fetchFollowers = async () => {
14-
try {
15-
const res = await fetch(`https://api.github.com/user/followers`, {
16-
headers: {
17-
Accept: 'application/vnd.github+json',
18-
//@ts-ignore
19-
Authorization: `Bearer ${session?.access_token}`,
20-
'X-Github-Api-Version': '2022-11-28'
21-
}
22-
});
23-
24-
if (!res.ok) throw new Error('Failed to fetch followers');
25-
return await res.json();
26-
} catch (error) {
27-
console.error('Error fetching followers:', error);
28-
return null;
29-
}
30-
};
31-
32-
const fetchUserInfo = async () => {
33-
try {
34-
const res = await fetch(`https://api.github.com/user`, {
35-
headers: {
36-
Accept: 'application/vnd.github+json',
37-
//@ts-ignore
38-
Authorization: `Bearer ${session?.access_token}`,
39-
'X-Github-Api-Version': '2022-11-28'
40-
}
41-
});
42-
43-
if (!res.ok) throw new Error('Failed to fetch user info');
44-
return await res.json();
45-
} catch (error) {
46-
console.error('Error fetching user info:', error);
47-
return null;
48-
}
49-
};
50-
51-
return {
52-
user: await fetchUserInfo(),
53-
session,
54-
followers: await fetchFollowers()
55-
};
5+
export const load:PageServerLoad = async (event) => {
6+
const session = await event.locals.auth();
7+
//console.log(session);
8+
9+
if (!session?.user) {
10+
throw redirect(303, '/login');
11+
}
12+
const followers = async () => {
13+
const res = await fetch(`https://api.github.com/user/followers`, {
14+
headers: {
15+
Accept: 'application/vnd.github+json',
16+
//@ts-ignore
17+
Authorization: `Bearer ${session.access_token}`,
18+
'X-Github-Api-Version': '2022-11-28'
19+
}
20+
});
21+
22+
return await res.json();
23+
};
24+
25+
const userInfo = async () => {
26+
const res = await fetch(`https://api.github.com/user`, {
27+
headers: {
28+
Accept: 'application/vnd.github+json',
29+
//@ts-ignore
30+
Authorization: `Bearer ${session?.access_token}`,
31+
'X-Github-Api-Version': '2022-11-28'
32+
}
33+
});
34+
35+
return await res.json();
36+
};
37+
38+
return {
39+
user: await userInfo(),
40+
session: await session,
41+
followers: await followers()
42+
};
5643
};

src/routes/profile/+page.svelte

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
const User = user.login;
1313
const url = `https://github.com/${User}`;
1414
15-
const formattedInfo = info.map(
16-
(/** @type {{ login: any; avatar_url: any; }} */ follower, /** @type {number} */ index) => ({
17-
id: index + 1,
18-
name: follower.login,
19-
designation: `${User} follower`,
20-
image: follower.avatar_url
21-
})
22-
);
15+
//console.log(user)
2316
</script>
2417

2518
<svelte:head>
@@ -90,19 +83,7 @@
9083
<strong class="text-black dark:text-white">{user.followers}</strong> Followers you know
9184
</span>
9285
</div>
93-
<div class="flex">
94-
<AnimatedTooltip items={formattedInfo} />
95-
<div class="ml-8">
96-
<a href={url} target="_blank">
97-
<Button
98-
borderRadius="1.75rem"
99-
className="bg-white dark:bg-slate-900 text-black dark:text-white border-neutral-200 dark:border-slate-800"
100-
>
101-
Github 🐱
102-
</Button></a
103-
>
104-
</div>
105-
</div>
86+
10687
</div>
10788
</div>
10889
</div>

src/routes/profile/+server.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import type { RequestHandler } from '@sveltejs/kit';
21

3-
export const GET: RequestHandler = async ({ locals }) => {
4-
//@ts-ignore
5-
if (!locals.session) {
6-
return new Response('Unauthorized', { status: 401 });
2+
export async function GET({ locals }) {
3+
//@ts-ignore
4+
const session = locals.session;
5+
6+
if (!session) {
7+
return new Response('Unauthorized', { status: 401 });
8+
}
9+
10+
return new Response(JSON.stringify(session), { status: 200 });
711
}
8-
9-
// Assuming 'session' in locals has a proper type that includes user data
10-
//@ts-ignore
11-
return new Response(JSON.stringify(locals.session), {
12-
headers: {
13-
'Content-Type': 'application/json'
14-
},
15-
status: 200
16-
});
17-
};
12+

src/routes/users/+page.ts renamed to src/routes/users/+page.server.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { redirect } from '@sveltejs/kit';
2-
import type { PageServerLoad } from './$types';
3-
4-
export const load:PageServerLoad = async (event) => {
5-
6-
const session = await event.locals.auth();
72

3+
export const load = async ({ parent }) => {
4+
const { session } = await parent();
85
const RandomUsers = Math.floor(Math.random() * 1000000);
96

107
if (!session?.user) {
@@ -25,4 +22,4 @@ export const load:PageServerLoad = async (event) => {
2522
return {
2623
RandomUsers: await getRandomUsers()
2724
};
28-
};
25+
};

src/routes/users/[slug]/+page.ts renamed to src/routes/users/[slug]/+page.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { redirect } from '@sveltejs/kit';
2-
import type { PageServerLoad } from './$types';
32

43
//@ts-ignore
5-
export const load:PageServerLoad = async ({ fetch, params, parent }) => {
4+
export const load = async ({ fetch, params, parent }) => {
65
const username = params.slug;
76

87
const { session } = await parent();
@@ -28,4 +27,4 @@ export const load:PageServerLoad = async ({ fetch, params, parent }) => {
2827
//@ts-ignore
2928
users: await fetchUsers()
3029
};
31-
};
30+
};

0 commit comments

Comments
 (0)