The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
adds images to the OneSignal integration guide
dshukertjr7f13bf979327
diff --git a/apps/docs/pages/guides/integrations/onesignal.mdx b/apps/docs/pages/guides/integrations/onesignal.mdxindex bed855a7a4b..d7d861e4f39 100644--- a/apps/docs/pages/guides/integrations/onesignal.mdx+++ b/apps/docs/pages/guides/integrations/onesignal.mdx@@ -7,7 +7,7 @@ export const meta = {'OneSignal allows you to send cloud messages to your users. Combine OneSignal with your Supabase apps and you can reach out to your users whenever there is a change in your database.',}-OneSignal is a tool that allows you to send messages across different channels such as the following to keep your users engaged.+[OneSignal](https://onesignal.com/) is a tool that allows you to send messages across different channels such as the following to keep your users engaged.- Push notifications- SMS@@ -20,7 +20,8 @@ We will have a simple UI and use Supabase’s Database Webhooks in conjunction wYou can find the complete example app along with the edge functions code to send the notifications [here](https://github.com/supabase-community/onesignal).-++## Step 1: Getting started@@ -49,8 +50,8 @@ After that, follow the instructions [here](https://documentation.onesignal.com/dThe Next.js app will have a login form for the user to sign in, and a button that they can press to make an order once they are signed in. Update the `index.tsx` file to the following.-```tsx-import { createClient, SupabaseClient, User } from '@supabase/supabase-js'+```tsx title="pages/index.tsx"+import { createClient, User } from '@supabase/supabase-js'import type { NextPage } from 'next'import Head from 'next/head'import React, { useEffect, useState } from 'react'@@ -68,6 +69,10 @@ const Home: NextPage = () => {const [oneSignalInitialized, setOneSignalInitialized] =useState<boolean>(false)+ /**+ * Initializes OneSignal SDK for a given Supabase User ID+ * @param uid Supabase User ID+ */const initializeOneSignal = async (uid: string) => {if (oneSignalInitialized) {return@@ -85,6 +90,33 @@ const Home: NextPage = () => {await OneSignal.setExternalUserId(uid)}+ const sendMagicLink = async (event: React.FormEvent<HTMLFormElement>) => {+ event.preventDefault()+ const { email } = Object.fromEntries(new FormData(event.currentTarget))+ if (typeof email !== 'string') return++ const { error } = await supabase.auth.signInWithOtp({ email })+ if (error) {+ alert(error.message)+ } else {+ alert('Check your email inbox')+ }+ }++ // Place a order with the selected price+ const submitOrder = async (event: React.FormEvent<HTMLFormElement>) => {+ event.preventDefault()+ const { price } = Object.fromEntries(new FormData(event.currentTarget))+ if (typeof price !== 'string') return++ const { error } = await supabase+ .from('orders')+ .insert({ price: Number(price) })+ if (error) {+ alert(error.message)+ }+ }+useEffect(() => {const initialize = async () => {const initialUser = (await supabase.auth.getUser())?.data.user@@ -111,29 +143,6 @@ const Home: NextPage = () => {}}, [])- const sendMagicLink = async (event: React.FormEvent<HTMLFormElement>) => {- event.preventDefault()- const { email } = Object.fromEntries(new FormData(event.currentTarget))- if (typeof email !== 'string') return-- const { error } = await supabase.auth.signInWithOtp({ email })- if (error) {- alert(error.message)- } else {- alert('Check your email inbox')- }- }-- // Create a order with price of $100- const submitOrder = async () => {- const { error } = await supabase.from('orders').insert({- price: 100,- })- if (error) {- alert(error.message)- }- }-return (<><Head>@@ -141,20 +150,28 @@ const Home: NextPage = () => {<link rel="icon" href="/favicon.ico" /></Head>- <main className="flex items-center justify-center min-h-screen">+ <main className="flex items-center justify-center min-h-screen bg-black">{user ? (- <div>+ <form className="flex flex-col space-y-2" onSubmit={submitOrder}>+ <select+ className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded block p-2"+ name="price"+ >+ <option value="100">$100</option>+ <option value="200">$200</option>+ <option value="300">$300</option>+ </select><button- onClick={submitOrder}+ type="submit"className="py-1 px-4 text-lg bg-green-400 rounded">Place an Order</button>- </div>+ </form>) : (<form className="flex flex-col space-y-2" onSubmit={sendMagicLink}><input- className="border-green-300 border rounded p-2"+ className="border-green-300 border rounded p-2 bg-transparent text-white"type="email"name="email"placeholder="Email"@@ -193,7 +210,7 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEYNEXT_PUBLIC_ONESIGNAL_APP_ID=YOUR_ONESIGNAL_APP_ID```-+## Step 3: Create the Edge Function@@ -260,7 +277,8 @@ ONESIGNAL_REST_API_KEY=YOUR_ONESIGNAL_REST_API_KEY`ONESIGNAL_APP_ID` and `ONESIGNAL_REST_API_KEY` can be found under `Settings > Keys & IDs` of your OneSignal app, and `USER_AUTH_KEY` can be found by going to `Account & API Keys` page by clicking your icon in the top right corner and scrolling to the `User Auth Key` section.-++Once your environment variables are filled in, you can run the following command to set the environment variable.@@ -287,7 +305,7 @@ create table if not exists public.orders ();```-As you can see, the `orders` table has 4 columns and 3 of them have default values. All we need to send from the front-end app is the price. That is why our insert statement looked very simple.+As you can see, the `orders` table has 4 columns and 3 of them have default values. That means all we need to send from the front-end app is the price. That is why our insert statement looked very simple.```tsxconst { error } = await supabase.from('orders').insert({@@ -297,11 +315,12 @@ const { error } = await supabase.from('orders').insert({Let’s also set up the webhook so that whenever a new row is inserted in the `orders` table, it calls the edge function. Go to `Database > Webhooks` and create a new Database Webhook. The table should be set to `orders` and Events should be inserted. The type should be HTTP Request, the HTTP method should be POST, and the URL should be the URL of your edge function. Hit confirm to save the webhook configuration.-+At this point, the app should be complete! Run your app locally with `npm run dev`, or deploy your app to a hosting service and see how you receive a push notification when you place an order!-++## Resourcesdiff --git a/apps/docs/public/img/guides/integrations/onesignal/app-ui.png b/apps/docs/public/img/guides/integrations/onesignal/app-ui.pngnew file mode 100644index 00000000000..e37e8b7a2d5Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/app-ui.png differdiff --git a/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.png b/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.pngnew file mode 100644index 00000000000..439fbec58daBinary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.png differdiff --git a/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.png b/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.pngnew file mode 100644index 00000000000..7e5672c05f3Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.png differdiff --git a/apps/docs/public/img/guides/integrations/onesignal/webhook.png b/apps/docs/public/img/guides/integrations/onesignal/webhook.pngnew file mode 100644index 00000000000..e09c2387721Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/webhook.png differ