投稿時間:2022-07-25 06:10:55 RSSフィード2022-07-25 06:00 分まとめ(12件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
海外TECH DEV Community SvelteKit with Supabase Auth Helpers https://dev.to/kvetoslavnovak/sveltekit-with-supabase-auth-helpers-578a SvelteKit with Supabase Auth HelpersSupabase has recently announced the revamped auth helpers for Supabase with SvelteKit support What are Auth Helpers According to Supabase one of the challenges has been creating a simple experience for server side rendering SSR environments Auth Helpers are a collection of framework specific utilities for Supabase Auth They allow you to implement secure applications with little effort These libraries include functions for protecting API routes and pages in your applications How to use Supabase Auth Helpers in SvelteKit Projet TL DRJust install these two npm packages npm install supabase auth helpers sveltekitnpm install supabase auth helpers svelte Detailed Tutorial Set Up SvelteKit ProjectWe will try to have a minimal bare bone project You are free to add any styling type checking etc later Supabase has quite nice examples using TypeScript available here Let name the project SvelteKitSupabaseAuthApp Just use the Skeleton project no TypeScript no ESLint no Prettier no Playwright npm create svelte latest SvelteKitSupabaseAuthAppcd SvelteKitSupabaseAuthAppnpm install Install Supabase Auth Helpers for SvelteKitnpm install supabase auth helpers sveltekitnpm install supabase auth helpers svelte Set Up Supabase ProjectLogin in Supabase and create a new project on the Supabase dashboard Go to Authentication gt Settings section and change User Sessions Site URL from http localhost to http localhost and save This is a localhost address where SvelteKit serves the project in developer mode This change was introduced with Vite Go to Settings gt API section and get the URL and anon key of your project Go back to your SvelteKitSupabaseAuthApp project and in its root create a new env file Replace VITE SUPABASE URL with the URL from previous step and VITE SUPABASE ANON KEY with anon key from previous step env Update these with your Supabase details from your project settings gt APIVITE SUPABASE URL https your project supabase coVITE SUPABASE ANON KEY your anon key Supabase Client CreationIn src folder create a new folder lib and in this lib folder create a new file sb js here we create supabaseClient using our credentials from env end export the supabaseClient so we can use its auth methods in our application We will use login with email in this app Supabase sends confirmation email automatically when a user signs ups lib sb jsimport createSupabaseClient from supabase auth helpers sveltekit const supabaseClient createSupabaseClient import meta env VITE SUPABASE URL import meta env VITE SUPABASE ANON KEY export supabaseClient HooksIn SvelteKit hook enables us to use two important functions a handle function and a getSession function The handle function runs every time the SvelteKit server receives a request The getSession function takes the event object and returns a session object that is accessible on the client so we can for example access data concerning user and cookies In src folder create a new file hooks js src hooks jsimport handleAuth from supabase auth helpers sveltekit import sequence from sveltejs kit hooks export const handle sequence handleAuth cookieOptions lifetime export const getSession async event gt const user accessToken event locals return user accessToken LayoutIn src routes folder create a new layout file layout svelte so we can not only have a simple layout but more importantly introduce our SupaAuthHelper component src routes layout svelte lt script gt import session from app stores import supabaseClient from lib sb import SupaAuthHelper from supabase auth helpers svelte lt script gt lt svelte head gt lt title gt Email and Password Demo Supabase Auth Helpers lt title gt lt svelte head gt lt SupaAuthHelper supabaseClient session gt lt main gt lt div gt lt h gt lt a href gt Supabase Auth Helpers Demo lt a gt lt h gt lt slot gt lt div gt if session user id lt a href api auth logout gt Sign out lt a gt if lt div gt lt div gt lt main gt lt SupaAuthHelper gt Sign up Page and RouteIn src routes folder create a new file signup svelte Just a simple sing up form src routes signup svelte lt script gt export let errors null export let values null export let message null lt script gt lt section gt lt div gt lt h gt Sign up lt h gt if errors lt div gt errors form lt div gt if if message lt div gt message lt div gt if lt form method post gt lt div gt lt label for email gt Email lt label gt lt p gt lt input id email name email value values email type email placeholder Email required gt lt p gt lt div gt lt div gt lt label for password gt Password lt label gt lt p gt lt input id password name password value values password type password placeholder Password required gt lt p gt lt div gt lt div gt lt p gt lt button gt Sign up lt button gt lt p gt lt div gt lt form gt lt div gt lt p gt Already have an account lt a href gt Sign in lt a gt lt p gt lt div gt lt div gt lt section gt In src routes folder create a new signup js file This endpoint points existing user to dashboard which is protected user only page or provides sing up data to supabaseClient We are also adding object specifying redirect when client clicks confirmation link in a confirmation email that Supabase will send him her src routes signup jsimport supabaseClient from lib sb export const GET async locals gt if the user is already logged in then redirect to the dashboard if locals user return status headers location dashboard return status export const POST async request url gt const data await request formData const email data get email const password data get password const errors const values email password const error await supabaseClient auth signUp email password redirectTo url origin logging in if error errors form error message return status body errors values return status body message Please check your email for a confirmation email Log in index Page and RouteIn src routes folder replace index svelte with this new one Just a simple login form src routes index svelte lt script gt export let errors export let values lt script gt lt section gt lt div gt lt h gt Sign in lt h gt if errors lt div gt errors form lt div gt if lt form method post gt lt div gt lt label for email gt Email lt label gt lt p gt lt input id email name email value values email type email placeholder Email required gt lt p gt lt div gt lt div gt lt label for password gt Password lt label gt lt p gt lt input id password name password value values password type password placeholder Password required gt lt p gt lt div gt lt div gt lt p gt lt button gt Sign in lt button gt lt p gt lt div gt lt form gt lt div gt lt p gt Don t have an account lt a href signup gt Sign up lt a gt lt p gt lt div gt lt div gt lt section gt In src routes folder create a new index js file This endpoint points existing user to dashboard which is protected user only page or provides login data to supabaseClient returned session is use for a cookie creation src routes index jsimport supabaseClient from lib sb export const GET async locals gt if locals user return status headers location dashboard return status export const POST async request url gt const data await request formData const email data get email const password data get password const headers location dashboard const errors const values email password const session error await supabaseClient auth signIn email password if error errors form error message return status body errors values if session const response await fetch url origin api auth callback method POST headers new Headers Content Type application json credentials same origin body JSON stringify event SIGNED IN session TODO Add helper inside of auth helpers sveltekit library to manage this better const cookies response headers get set cookie split SameSite Lax map cookie gt if cookie includes SameSite Lax cookie SameSite Lax return cookie headers Set Cookie cookies return status headers Email confirmation redirect pageIn src routes folder create a new file logging in blank svelte so we can check if the user redirected after email confirmation has been already set in session store We will also provide a special layout for this case later on During my tests the redirect and session store were quite fast so this page may be visible rather rarely src routes logging in blank svelte lt script gt import session from app stores import goto from app navigation import page from app stores let redirectPath dashboard const redirectTo page url searchParams get redirect if redirectTo redirectPath redirectTo check if user has been set in session store then redirect if session user id goto redirectPath lt script gt lt section gt lt div gt lt progress class progress max gt lt div gt lt div gt Signing in from the email confirmation link lt div gt lt section gt lt style gt progress indeterminate animation duration s lt style gt Dashboard Page and Route protected users only pageIn src routes folder create a new file dashboard svelte where we display some data about user stored by Supabase src routes dashboard svelte lt script gt export let user lt script gt lt div gt lt h gt This is protected route accesible only for ligged users lt h gt lt p gt Hello user user email lt p gt lt div gt lt div gt lt p gt User user email details lt p gt lt pre gt JSON stringify user null lt pre gt lt div gt In src routes folder create a new dashboard js file src routes dashboard jsimport supabaseServerClient withApiAuth from supabase auth helpers sveltekit export const GET async locals request gt withApiAuth redirectTo user locals user async gt const data await supabaseServerClient request from test select return body data user locals user Email Confirmation Redirect LayoutIn src routes folder create a new file layout blank svelte where we are having a special named layout for email confirmation redirect as mentioned earlier src routes layout blank svelte lt script gt import session from app stores import supabaseClient from lib sb import SupaAuthHelper from supabase auth helpers svelte lt script gt lt svelte head gt lt title gt Email and Password Demo Supabase Auth Helpers lt title gt lt svelte head gt lt SupaAuthHelper supabaseClient session gt lt slot gt lt SupaAuthHelper gt I hope this tutorial was useful Big thank to Supabase guys for SvelteKit Auth Helpers their examples where true source for this article Because I am really no auth expert especial y concerning SSR all comments corrections or enhancements are welcomed 2022-07-24 20:25:00
Apple AppleInsider - Frontpage News The best alternatives to Apple's Dark Sky weather app https://appleinsider.com/articles/22/07/24/the-best-alternatives-to-apples-dark-sky-weather-app?utm_medium=rss The best alternatives to Apple x s Dark Sky weather appApple s Dark Sky iOS app will stop working on December Here are some of our favorite alternative weather apps Dark SkyDark Sky is one of the most popular weather apps for smartphones and browsers However since Apple acquired it the app has been living on borrowed time Read more 2022-07-24 20:45:27
海外TECH Engadget Marvel's new Disney+ 'Daredevil' series will arrive in 2024 https://www.engadget.com/disney-plus-daredevil-born-again-announced-202524158.html?src=rss Marvel x s new Disney x Daredevil x series will arrive in It s official Nearly four years after Netflix canceled Daredevil and the series more recently made its way over to Disney Disney confirmed it s developing a new episode live action TV show starring the blind superhero On Saturday Marvel announced Daredevil Born Again nbsp and shared that stars Charlie Cox and Vincent D Onofrio would reprise their roles as Daredevil and Kingpin News that the company planned to revive Daredevil first came to light in May with Variety reporting that Disney had hired Matt Corman and Chris Ord to write and produce the series Disney currently plans to begin streaming Born Again sometime in the spring of Before then Marvel fans can look forward to I Am Groot and She Hulk Attorney at Law arriving on Disney Both shows got new trailers during San Diego Comic Con this weekend 2022-07-24 20:25:24
海外科学 NYT > Science China Launches Wentian Space Station Module With Giant Rocket https://www.nytimes.com/2022/07/24/science/china-space-rocket-long-march.html booster 2022-07-24 20:39:57
ビジネス ダイヤモンド・オンライン - 新着記事 三菱商事も参戦「サーモン陸上養殖」、商社の競争過熱もスシロートップがダメ出しの悲哀 - 商社 食料部門の悲哀―非資源の大黒柱 https://diamond.jp/articles/-/306816 foodlifecompanies 2022-07-25 05:25:00
ビジネス ダイヤモンド・オンライン - 新着記事 親ガチャと嘆く前に!大学をお金で諦めない「返還不要の奨学金」全国111大学情報 - 大学2022 劇変の序列・入試・就職 https://diamond.jp/articles/-/306467 親ガチャと嘆く前に大学をお金で諦めない「返還不要の奨学金」全国大学情報大学劇変の序列・入試・就職コロナ禍による経済事情の悪化で、中退や休学に追い込まれる大学生や、進学自体を断念する高校生が増えている。 2022-07-25 05:20:00
ビジネス ダイヤモンド・オンライン - 新着記事 FRBの7月利上げで、日本経済が覚悟を迫られる「3つの影響」とは - 伊藤忠総研「世界経済ニュースの読み解き方」 https://diamond.jp/articles/-/306842 世界経済 2022-07-25 05:15:00
ビジネス ダイヤモンド・オンライン - 新着記事 理系大学62校の本当の「序列」が判明!偏差値含む3指標で独自に評価 - 大学2022 劇変の序列・入試・就職 https://diamond.jp/articles/-/306466 大学院進学率 2022-07-25 05:10:00
ビジネス ダイヤモンド・オンライン - 新着記事 伊藤博文、犬養毅…要人銃撃が連鎖した時代と現代との「意外な類似点」 - 新説・新発見!今こそ学ぶ「歴史・地理」 https://diamond.jp/articles/-/306834 伊藤博文、犬養毅…要人銃撃が連鎖した時代と現代との「意外な類似点」新説・新発見今こそ学ぶ「歴史・地理」参院選の選挙期間終盤、月日に安倍晋三元首相が銃撃され、命を落とした。 2022-07-25 05:05:00
ビジネス 電通報 | 広告業界動向とマーケティングのコラム・ニュース Shopify Plusを使ったECサイト開発の要件定義ってどうやるの?~電通デジタルの要件定義フレームワーク~ https://dentsu-ho.com/articles/8262 shopifyplus 2022-07-25 06:00:00
北海道 北海道新聞 相互理解へ留学生ら熱唱 11カ国、コロナで3年ぶり https://www.hokkaido-np.co.jp/article/709654/ 技能実習生 2022-07-25 05:32:00
ビジネス 東洋経済オンライン 第一三共、「時価総額7兆円」支える乳がん薬の底力 主力製品「エンハーツ」の投与対象が大幅拡大か | 医薬品・バイオ | 東洋経済オンライン https://toyokeizai.net/articles/-/606059?utm_source=rss&utm_medium=http&utm_campaign=link_back 時価総額 2022-07-25 05:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)