0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsのプロジェクトとSupabaseのプロジェクトをリンクさせる方法

Posted at

Next.jsとSupabaseのプロジェクトは作成している前提で話を進める。

1. Next.js プロジェクトに Supabase クライアントをインストール

ターミナル
npm install @supabase/supabase-js

2. Supabase クライアントを作成

app/supabase/supabase.ts に以下を記述する

supabase.ts
import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!

export const supabase = createClient(supabaseUrl, supabaseAnonKey)

3. 環境変数を .env.local に設定

プロジェクトフォルダ直下に.env.localを作成し、以下を記述

.env.local
NEXT_PUBLIC_SUPABASE_URL=https://xxxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Supabaseのプロジェクトにアクセスし、
Project Settings -> Data API から Project URL、anon public key を取得する。
NEXT_PUBLIC_SUPABASE_URL に Project URL、
NEXT_PUBLIC_SUPABASE_ANON_KEY に anon public key をペーストする。

.env.local は Git 管理対象外にしておく。( .gitignore に追加する。)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?