Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

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.mdx
index 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 w
You can find the complete example app along with the edge functions code to send the notifications [here](https://github.com/supabase-community/onesignal).
-![Screen Shot 2022-12-14 at 0.17.03.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e8f411e8-456c-466c-b26d-389687ada880/Screen_Shot_2022-12-14_at_0.17.03.png)
+![Ordering app UI](/docs/img/guides/integrations/onesignal/app-ui.png)
+
## Step 1: Getting started
@@ -49,8 +50,8 @@ After that, follow the instructions [here](https://documentation.onesignal.com/d
The 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_KEY
NEXT_PUBLIC_ONESIGNAL_APP_ID=YOUR_ONESIGNAL_APP_ID
```
-![Screen Shot 2022-12-14 at 0.39.24.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4ea80251-3271-495a-a6e0-f68466403503/Screen_Shot_2022-12-14_at_0.39.24.png)
+![Where to find OneSignal App ID](/docs/img/guides/integrations/onesignal/onesignal-app-id.png)
## 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.
-![Screen Shot 2022-12-14 at 0.39.03.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/02c4f84d-2b0b-49ec-91b8-0da2c3ccc9ca/Screen_Shot_2022-12-14_at_0.39.03.png)
+![Where to find OneSignal User Auth Key](/docs/img/guides/integrations/onesignal/onesignal-api-key.png)
+
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.
```tsx
const { 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.
-![Screen Shot 2022-12-14 at 0.13.52.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/545e22f9-fc66-437d-8a16-6d2226a08192/Screen_Shot_2022-12-14_at_0.13.52.png)
+![Supabase Webhooks configuration](/docs/img/guides/integrations/onesignal/webhook.png)
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!
-![Screen Shot 2022-12-14 at 0.17.03.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ec6e3b60-b024-4172-9b9b-35fb2b123499/Screen_Shot_2022-12-14_at_0.17.03.png)
+![Ordering app UI](/docs/img/guides/integrations/onesignal/app-ui.png)
+
## Resources
diff --git a/apps/docs/public/img/guides/integrations/onesignal/app-ui.png b/apps/docs/public/img/guides/integrations/onesignal/app-ui.png
new file mode 100644
index 00000000000..e37e8b7a2d5
Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/app-ui.png differ
diff --git a/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.png b/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.png
new file mode 100644
index 00000000000..439fbec58da
Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/onesignal-api-key.png differ
diff --git a/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.png b/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.png
new file mode 100644
index 00000000000..7e5672c05f3
Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/onesignal-app-id.png differ
diff --git a/apps/docs/public/img/guides/integrations/onesignal/webhook.png b/apps/docs/public/img/guides/integrations/onesignal/webhook.png
new file mode 100644
index 00000000000..e09c2387721
Binary files /dev/null and b/apps/docs/public/img/guides/integrations/onesignal/webhook.png differ