Skip to content

Commit

Permalink
Fetch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
massimobiagioli committed Mar 23, 2023
1 parent ed54e33 commit 0090334
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/lib/features/device/getUserDevices/getUserDevices.ts
@@ -0,0 +1,18 @@
import type {SupabaseClient} from "@supabase/supabase-js";
import type {Database} from "../../../supabase/database.types";

const GetUserDevices = (supabase: SupabaseClient<Database>) =>
async (owner: string) => {
const {data, error} = await supabase
.from('device')
.select()
.eq('owner', owner);

if (error) {
console.error(error);
}

return data;
}

export default GetUserDevices;
17 changes: 17 additions & 0 deletions src/routes/devices/+page.svelte
@@ -1 +1,18 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
$: ({ devices } = data);
</script>

<div>WIP: Devices</div>

{#if devices?.length}
<ul>
{#each devices as device}
<li>{device.name}</li>
{/each}
</ul>
{:else}
<div>No devices found</div>
{/if}
17 changes: 17 additions & 0 deletions src/routes/devices/+page.ts
@@ -0,0 +1,17 @@
import { redirect } from '@sveltejs/kit';
import GetUserDevices from "../../lib/features/device/getUserDevices/getUserDevices";
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ parent }) => {
const { supabase, session } = await parent();
if (!session) {
throw redirect(303, '/');
}

const getUserDevices = GetUserDevices(supabase);
const devices = await getUserDevices(session.user.id);

return {
devices
};
};
1 change: 0 additions & 1 deletion src/routes/user-profile/+page.svelte

This file was deleted.

0 comments on commit 0090334

Please sign in to comment.