Skip to content

Commit

Permalink
Sveltekit 2 migration!
Browse files Browse the repository at this point in the history
This is just running `npx svelte-migrate@latest sveltekit-2` and fixing package conflicts.

Next step: run through rest of https://kit.svelte.dev/docs/migrating-to-sveltekit-2
  • Loading branch information
scosman committed May 22, 2024
1 parent d7fdeb9 commit 7daaf4a
Show file tree
Hide file tree
Showing 14 changed files with 675 additions and 393 deletions.
987 changes: 637 additions & 350 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"format_check": "prettier --check --plugin prettier-plugin-svelte ./"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.30.4",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tailwindcss/typography": "^0.5.13",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.19.0",
Expand All @@ -32,12 +33,12 @@
"svelte-check": "^3.4.3",
"tailwindcss": "^3.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vitest": "^0.34.0"
"vite": "^5.0.0",
"vitest": "^1.0.0"
},
"type": "module",
"dependencies": {
"@supabase/auth-helpers-sveltekit": "^0.10.2",
"@supabase/auth-helpers-sveltekit": "^0.13.0",
"@supabase/auth-ui-svelte": "^0.2.9",
"@supabase/supabase-js": "^2.33.0",
"stripe": "^13.3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(admin)/account/(menu)/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const actions = {
const { session } = await safeGetSession()
if (session) {
await supabase.auth.signOut()
throw redirect(303, "/")
redirect(303, "/")
}
},
}
6 changes: 3 additions & 3 deletions src/routes/(admin)/account/(menu)/billing/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export const load: PageServerLoad = async ({
}) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
}
Expand All @@ -31,7 +31,7 @@ export const load: PageServerLoad = async ({
customerId,
})
if (fetchErr) {
throw error(500, {
error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
}
Expand Down
11 changes: 4 additions & 7 deletions src/routes/(admin)/account/(menu)/billing/manage/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export const load: PageServerLoad = async ({
}) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
error(500, {
message: "Unknown error (PCID). If issue persists, please contact us.",
})
}
Expand All @@ -32,11 +32,8 @@ export const load: PageServerLoad = async ({
})
portalLink = portalSession?.url
} catch (e) {
throw error(
500,
"Unknown error (PSE). If issue persists, please contact us.",
)
error(500, "Unknown error (PSE). If issue persists, please contact us.")
}

throw redirect(303, portalLink ?? "/account/billing")
redirect(303, portalLink ?? "/account/billing")
}
2 changes: 1 addition & 1 deletion src/routes/(admin)/account/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const load: LayoutServerLoad = async ({
const { session } = await safeGetSession()

if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const { data: profile } = await supabase
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(admin)/account/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const load = async ({ fetch, data, depends, url }) => {
!_hasFullProfile(profile) &&
url.pathname !== createProfilePath
) {
throw redirect(303, createProfilePath)
redirect(303, createProfilePath)
}

return { supabase, session, profile }
Expand Down
18 changes: 9 additions & 9 deletions src/routes/(admin)/account/api/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const actions = {
updateEmail: async ({ request, locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const formData = await request.formData()
Expand Down Expand Up @@ -46,7 +46,7 @@ export const actions = {
updatePassword: async ({ request, locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const formData = await request.formData()
Expand Down Expand Up @@ -124,7 +124,7 @@ export const actions = {
})
if (error) {
// The user was logged out because of bad password. Redirect to error page explaining.
throw redirect(303, "/login/current_password_error")
redirect(303, "/login/current_password_error")
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export const actions = {
}) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const formData = await request.formData()
Expand All @@ -174,7 +174,7 @@ export const actions = {
})
if (pwError) {
// The user was logged out because of bad password. Redirect to error page explaining.
throw redirect(303, "/login/current_password_error")
redirect(303, "/login/current_password_error")
}

const { error } = await supabaseServiceRole.auth.admin.deleteUser(
Expand All @@ -189,12 +189,12 @@ export const actions = {
}

await supabase.auth.signOut()
throw redirect(303, "/")
redirect(303, "/")
},
updateProfile: async ({ request, locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

const formData = await request.formData()
Expand Down Expand Up @@ -265,9 +265,9 @@ export const actions = {
const { session } = await safeGetSession()
if (session) {
await supabase.auth.signOut()
throw redirect(303, "/")
redirect(303, "/")
} else {
throw redirect(303, "/")
redirect(303, "/")
}
},
}
2 changes: 1 addition & 1 deletion src/routes/(admin)/account/create_profile/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function load({ parent }) {

// They completed their profile! Redirect to "Select a Plan" screen.
if (_hasFullProfile(data?.profile)) {
throw redirect(303, "/account/select_plan")
redirect(303, "/account/select_plan")
}

return data
Expand Down
15 changes: 6 additions & 9 deletions src/routes/(admin)/account/subscribe/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export const load: PageServerLoad = async ({
}) => {
const { session } = await safeGetSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login")
}

if (params.slug === "free_plan") {
// plan with no stripe_price_id. Redirect to account home
throw redirect(303, "/account")
redirect(303, "/account")
}

const { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
}
Expand All @@ -38,7 +38,7 @@ export const load: PageServerLoad = async ({
})
if (primarySubscription) {
// User already has plan, we shouldn't let them buy another
throw redirect(303, "/account/billing")
redirect(303, "/account/billing")
}

let checkoutUrl
Expand All @@ -57,11 +57,8 @@ export const load: PageServerLoad = async ({
})
checkoutUrl = stripeSession.url
} catch (e) {
throw error(
500,
"Unknown Error (SSE): If issue persists please contact us.",
)
error(500, "Unknown Error (SSE): If issue persists please contact us.")
}

throw redirect(303, checkoutUrl ?? "/pricing")
redirect(303, checkoutUrl ?? "/pricing")
}
6 changes: 3 additions & 3 deletions src/routes/(marketing)/auth/callback/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const GET = async ({ url, locals: { supabase } }) => {
// If you open in another browser, need to redirect to login.
// Should not display error
if (isAuthApiError(error)) {
throw redirect(303, "/login/sign_in?verified=true")
redirect(303, "/login/sign_in?verified=true")
} else {
throw error
}
Expand All @@ -20,8 +20,8 @@ export const GET = async ({ url, locals: { supabase } }) => {

const next = url.searchParams.get("next")
if (next) {
throw redirect(303, next)
redirect(303, next)
}

throw redirect(303, "/account")
redirect(303, "/account")
}
2 changes: 1 addition & 1 deletion src/routes/(marketing)/blog/(posts)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
}
if (!searchPost) {
throw error(404, "Blog post not found")
error(404, "Blog post not found")
}
return searchPost
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(marketing)/login/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const load: LayoutServerLoad = async ({

// if the user is already logged in return them to the account page
if (session) {
throw redirect(303, "/account")
redirect(303, "/account")
}

return {
Expand Down
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adapter from "@sveltejs/adapter-auto"
import { vitePreprocess } from "@sveltejs/kit/vite"
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"

/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand Down

0 comments on commit 7daaf4a

Please sign in to comment.