Skip to content

Commit

Permalink
migration to Sveltekit 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bbr27 committed Jan 19, 2024
1 parent af5d0a0 commit 9baa983
Show file tree
Hide file tree
Showing 14 changed files with 592 additions and 324 deletions.
817 changes: 542 additions & 275 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
"format": "prettier --write --plugin prettier-plugin-svelte ./src"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.27.6",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^1.20.4",
"@sveltejs/vite-plugin-svelte": "^2.4.1",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.15",
"daisyui": "^3.5.1",
"eslint": "^8.28.0",
"eslint-plugin-svelte": "^2.30.0",
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.0.5",
"svelte-check": "^3.4.3",
"tailwindcss": "^3.3.3",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vitest": "^0.34.0"
"vite": "^5.0.0",
"vitest": "^1.0.0"
},
"type": "module",
"dependencies": {
Expand All @@ -38,4 +39,4 @@
"@supabase/supabase-js": "^2.33.0",
"stripe": "^13.3.0"
}
}
}
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 getSession()
if (session) {
await supabase.auth.signOut()
throw redirect(303, "/")
redirect(303, "/");
}
},
}
14 changes: 7 additions & 7 deletions src/routes/(admin)/account/(menu)/billing/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export const load: PageServerLoad = async ({
}) => {
const session = await getSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login");
}

let { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
error(500, {
message: "Unknown error. If issue persists, please contact us.",
});
}

const {
Expand All @@ -33,9 +33,9 @@ export const load: PageServerLoad = async ({
userId: session.user.id,
})
if (fetchErr) {
throw error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
error(500, {
message: "Unknown error. If issue persists, please contact us.",
});
}

return {
Expand Down
18 changes: 9 additions & 9 deletions src/routes/(admin)/account/(menu)/billing/manage/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export const load: PageServerLoad = async ({
}) => {
const session = await getSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login");
}

let { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
message: "Unknown error (PCID). If issue persists, please contact us.",
})
error(500, {
message: "Unknown error (PCID). If issue persists, please contact us.",
});
}

let portalLink
Expand All @@ -32,11 +32,11 @@ 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: PageServerLoad = async ({
const session = await getSession()

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 @@ -24,7 +24,7 @@ export const load = async ({ fetch, data, depends, url }) => {

const createProfilePath = "/account/create_profile"
if (!_hasFullProfile(profile) && url.pathname !== createProfilePath) {
throw redirect(303, createProfilePath)
redirect(303, createProfilePath);
}

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

const formData = await request.formData()
Expand Down Expand Up @@ -118,7 +118,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 All @@ -143,7 +143,7 @@ export const actions = {
deleteAccount: async ({ request, locals: { supabase, supabaseServiceRole, getSession } }) => {
const session = await getSession()
if (!session) {
throw redirect(303, "/login")
redirect(303, "/login");
}

const formData = await request.formData()
Expand All @@ -164,7 +164,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(session.user.id, true)
Expand All @@ -176,7 +176,7 @@ export const actions = {
}

await supabase.auth.signOut()
throw redirect(303, "/")
redirect(303, "/");
},
updateProfile: async ({ request, locals: { supabase, getSession } }) => {
const formData = await request.formData()
Expand Down Expand Up @@ -239,7 +239,7 @@ export const actions = {
const session = await getSession()
if (session) {
await supabase.auth.signOut()
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
22 changes: 11 additions & 11 deletions src/routes/(admin)/account/subscribe/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ export const load: PageServerLoad = async ({
}) => {
const session = await getSession()
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");
}

let { error: idError, customerId } = await getOrCreateCustomerId({
supabaseServiceRole,
session,
})
if (idError || !customerId) {
throw error(500, {
message: "Unknown error. If issue persists, please contact us.",
})
error(500, {
message: "Unknown error. If issue persists, please contact us.",
});
}

const { primarySubscription } = await fetchSubscription({
Expand All @@ -40,7 +40,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 @@ -59,11 +59,11 @@ 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)/login/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const load: PageServerLoad = 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 src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->
<div
class="fixed w-full top-0 right-0 left-0 h-1 z-50 bg-primary"
in:slide={{ delay: 100, duration: 12000, axis: "x", easing: expoOut }}
in:slide|global={{ delay: 100, duration: 12000, axis: "x", easing: expoOut }}
></div>
{/if}
<slot />
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 9baa983

Please sign in to comment.