Upgrade to Pro — share decks privately, control downloads, hide ads and more …

supabaseとSvelteKitで作るバックエンドレスなサーバーレスWebサイト / Cr...

shiro seike
November 18, 2023

supabaseとSvelteKitで作るバックエンドレスなサーバーレスWebサイト / Creating with supabase and SvelteKit Backend-less serverless websites

フロントエンドカンファレンス沖縄2023
https://frontend-conf.okinawa.jp

shiro seike

November 18, 2023
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. 自己 @seike 46 0 - - @seike 46 0 -

    AWS Community Builder Serverless - Fusic - / 門 - / - - PHP - JAWS Days AWS Devday - Serverless Days Tokyo - - 大 工 子工 - PHP - 2
  2. Write less code - Svelte 6 <script> let a =

    1 ; let b = 2 ; </script> <input type="number" bind:value={a}> <input type="number" bind:value={b}> <p>{a} + {b} = {a + b}</p> let State bind 行 方 築 行 [a] input p [a]
  3. Write less code + Truly reactive 7 <script> let a

    = 1 ; let b = 2 ; </script> <input type="number" bind:value={a}> <input type="number" bind:value={b}> <p>{a} + {b} = {a + b}</p> Svelte ⾒
  4. TEMPLATE SYNTAX 8 {#if porridge.temperature > 1 00 } <p>too

    hot!</p> {:else if 8 0 > porridge.temperature} <p>too cold!</p> {:else} <p>just right!</p> {/if} {#each items as item} <li>{item.name} x {item.qty}</li> {/each} {#await promise} <p>waiting for the promise to resolve...</p> {:then value} <p>The value is {value}</p> {:catch error} <p>Something went wrong: {error.message}</p> {/await} {#key value} <div transition:fade>{value}</div> {/key} {#if }... {:else if } {/if} {#each as name, index} ... {/each} {#await }... {:then name}... {:catch name} … {/await} {#key }... {/key}
  5. SvelteKit Svelte Vite Rollup 用 っ   URL っ (SSR)

    生 (SSG)  高 SEO っ   っ   16
  6. Routing 18 src/routes/+page.svelte -> / <h 1 >Hello and welcome

    to my site!</h 1 > <a href="/about">About my site</a> src/routes/about/+page.svelte -> /about <h 1 >About this site</h 1 > <p>TODO...</p> <a href= /">Home</a> src/routes/blog/[slug]/+page.svelte -> blog/hoge <script> /** @type {import('./$types').PageData} */ export let data; </script> <h 1 >{data.title}</h 1 > <div>{@html data.content}</div> SvelteKit 用 src/routes URL +error.svelte +layout.svelte API +server.js URL
  7. Loading data 19 src/routes/blog/[slug]/+page.js /** @type {import('./$types').PageLoad} */ export function

    load({ params }) {   return {    post: {     title: `Title for ${params.slug} goes here`,     content: `Content for ${params.slug} goes here`    }   }; } src/routes/blog/[slug]/+page.svelte <script>   /** @type {import('./$types').PageData} */   export let data; </script> <h 1 >{data.post.title}</h 1 > <div>{@html data.post.content}</div> +page.svelte load +page.js load page data 用 Layout data +page.server.js cookies headers
  8. Form actions 20 src/routes/login/+page.server.js /** @type {import('./$types').Actions} */ export const

    actions = {    default: async (event) => {    // TODO log the user in   } }; src/routes/login/+page.svelte <form method="POST">   <label>    Email    <input name="email" type="email">   </label>   <label>    Password    <input name="password" type="password">   </label>   <button>Log in</button> </form> +page.server.js actions <form> 用 POST 築 築 ⾒ / 築 login -> ?/login register -> ?/register
  9. Page options 21 +page.js/+page.server.js/+server.js export const prerender = true; +page.js

    export const ssr = true; っ 生 HTML 生 生 っ 生 SSR 生 示
  10. State management 22 +page.server.js let user; /** @type {import('./$types').Actions} */

    export const actions = {   default: async ({ request }) => {    const data = await request.formData();    // NEVER DO THIS!    user = {     name: data.get( ‘ name'),     embarrassingSecret: data.get( ‘ secret')    };   } } っ state user っload 用 っcontext store
  11. 03

  12. - API - - API 用 - - DB 用

    sqlite - - - - っ 欠     -> 身 築 or 24
  13. supabase っPostgreSQL supabase PostgreSQL っ っ Google GitHub Facebook っ

    自 API SQL RESTful API 自 PostgREST 用 っ 行 っ 一 自 行 っ GitHub 用 -> EC 2 28
  14. Client 生 supabase Client URL KEY anonkey KEY anonkey CRUD

    29 PUBLIC_SUPABASE_URL PUBLIC_SUPABASE_KEY
  15. Row Level Security PostgreSQL 用 row SQL 人 見  

    Row Level Security   DB   31 supabase Row Level Security Firebase 比 @dshukertjr https://qiita.com/dshukertjr/items/ 0 5 372 4 367 fda 267 8 f 2 41
  16. 34 API from 行 select insert update delete 用 行

    match like in 稿 行 order limit 用 ORM 用  
  17. SvelteKit supabase ⾒ SQL ⾒ Model Model 用 SQL SQL

    行 手 SvelteKit supabase 自 API 生 40
  18. 文 っFree   Free 人 用 PoC 用 用  

    2 ⾒ 用 ⾒ PRO 用   用 PRO   っ  一方 手  自 Amazon RDS 用 44
  19. 47

  20. 48

  21. 07

  22. 52 SvelteKit Point 1 supabase Point 2 SvelteKit X supabase

    Point 3 SvelteKit X supabase Point 4