Skip to content

Commit

Permalink
fix: read notes
Browse files Browse the repository at this point in the history
fixes:
- pages that filter data (/scripts, /tutorials, /scripters, /stats) had a routing bug that caused the back button to not work as expected.
- upgraded the supabases auth-helpers-sveltekit to the new supabase/ssr which should fix some auth bugs
refactors:
- several repeated  patterns were removed in favor of loops
- paginator component used in pages that load a lot of data has been rewritten
- the way that data reacted to filters has been reworked, should have the same exact behaviour but without listeners which is good for resources :)
  • Loading branch information
Torwent committed Jan 13, 2024
1 parent 5374454 commit 9435126
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 418 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@playwright/test": "^1.40.1",
"@skeletonlabs/skeleton": "^1.12.0",
"@supabase/auth-helpers-sveltekit": "^0.10.7",
"@sveltejs/kit": "^1.30.3",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
Expand Down Expand Up @@ -48,16 +47,14 @@
},
"type": "module",
"dependencies": {
"@dicebear/bottts": "^6.0.4",
"@dicebear/core": "^6.0.4",
"@enviro/metadata": "^1.5.1",
"@floating-ui/dom": "^1.5.3",
"@stripe/connect-js": "^3.2.0",
"@supabase/ssr": "^0.0.10",
"@supabase/supabase-js": "^2.39.1",
"@sveltejs/adapter-vercel": "^3.1.0",
"file-saver": "^2.0.5",
"highlight.js": "^11.9.0",
"install": "^0.13.0",
"jimp": "^0.22.10",
"jszip": "^3.10.1",
"lucide-svelte": "^0.259.0",
Expand Down
124 changes: 30 additions & 94 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SupabaseClient, Session } from "@supabase/supabase-js"
import type { SupabaseClient, Session, User } from "@supabase/supabase-js"
import type { Database } from "$lib/types/supabase"
import type { Profile } from "$lib/types/collection"

Expand All @@ -7,6 +7,7 @@ declare global {
interface Locals {
supabaseServer: SupabaseClient<Database>
getSession(): Promise<Session | null>
getUser(): Promise<User | null>
getProfile(): Promise<Profile | null>
profile: Profile | null
}
Expand Down
29 changes: 21 additions & 8 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { error, type Handle } from "@sveltejs/kit"
import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from "$env/static/public"
import { createSupabaseServerClient } from "@supabase/auth-helpers-sveltekit"
import { createServerClient } from "@supabase/ssr"
import type { Profile } from "$lib/types/collection"

export const handle: Handle = async ({ event, resolve }) => {
const start = performance.now()

const { url, locals } = event

locals.supabaseServer = createSupabaseServerClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event
locals.supabaseServer = createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
cookies: {
get: (key) => event.cookies.get(key),
set: (key, value, options) => {
event.cookies.set(key, value, options)
},
remove: (key, options) => {
event.cookies.delete(key, options)
}
}
})

locals.getSession = async () => {
Expand All @@ -21,11 +27,18 @@ export const handle: Handle = async ({ event, resolve }) => {
return session
}

locals.getUser = async () => {
const {
data: { user }
} = await locals.supabaseServer.auth.getUser()
return user
}

locals.getProfile = async () => {
const session = await locals.getSession()
if (!session) return null
const user = await locals.getUser()
if (!user) return null

const id = session.user.id
const id = user.id
const { data, error: err } = await locals.supabaseServer
.schema("profiles")
.from("profiles")
Expand Down
Loading

0 comments on commit 9435126

Please sign in to comment.