🔘 A small scale chat application. Built with Nuxt 3 and Supabase.
| apps | ||
| .gitignore | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
| turbo.json | ||
| yarn.lock | ||
Ping ⏺️
A small scale chat application.
Hosting locally
Since Ping uses Supabase to handle authentication and storing data, you'll need to setup the schema accordingly.
If something goes wrong, or you need help, please don't hesitate to create a new issue or reach out via email.
Authentication
- Go to Supabase and sign in.
- Create a new project, give it a name, a strong password and choose a location for it.
- Go to "Authentication", "Providers", click "Email" and disable the email provider.
- Scroll down, click on "GitHub", enable it, and copy the callback URL. You'll probably notice that you need a client id and secret.
- Head over to GitHub and create a new OAuth app.
- Fill in the fields accordingly, and in the "Authorization callback URL" field, paste the "callback URL" you copied earlier.
- Click "Register Application".
- On the next page, copy your "Client ID" and paste it into the same field on Supabase.
- Then click on "Generate a new client secret", copy the secret and paste that into Supabase too.
- You can now close GitHub. Make sure to save the details in Supabase.
Tables
Congrats, you just setup authentication. Now let's get the database tables setup.
- Go to "Table editor" and create a new table called
rooms, enable realtime and save. - Then create another table called
messages, enable realtime and save. - When creating columns, make sure that all the "Constraints" are disabled Example
messages table
- On the messages table, create the columns
room_idwith a foreign key relation topublic.rooms.id, action set toCascade(Example) - Create the column
content,usernameandavatarwith a text type. - Then create an
author_idcolumn with a foreign key relation toauth.users.id, and action set toCascade(Example)
rooms table
- On the
roomstable, create the columnsnameanddescriptionwith a text type. - Then create an
author_idcolumn with a foreign key relation toauth.users.id, and action set toCascade(Example)
RLS (Row Level Security)
Your tables are now setup! One last thing, the RLS (row level security) policies.
- Go back to 'Authentication' and click 'Policies'.
- When creating policies, make sure you click "For full customization".
messages table
- Create a new policy called "Enable insert", allow the operation
INSERT, with the target role ofauthenticated, and theWITH CHECK expressionequalstrue. Click "Review" and "Save policy". - Do the same thing as step 3, but name it "Enable read", and instead of allowing the operation
INSERT, allowSELECT.
rooms table
- Create a new policy called "Enable delete", allow the operation
DELETE, with no target roles, and theUSING expressionequals(auth.uid() = author_id). Click "Review" and "Save policy". - Follow steps 3 and 4 again on the rows table.
Setting up Ping
Supabase has been successfully configured. All we need to do now is get the Supabase instance URL, anon key, and service key!
- Clone the repo and create a
.envfile. - Go to 'Project Settings', then 'API'.
- Paste your Project URL,
anonkey andservice_rolekey into your env like the example below.
SUPABASE_URL="https://************.supabase.co"
SUPABASE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.***********************"
SUPABASE_SERVICE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.***********************"
- Run
pnpm dev -oto start the development server orpnpm buildto build Ping.
Congrats! You just got yourself your very own Ping instance running on your own Supabase project.
Help
If more help is needed, you can contact me by e-mail or tweet to me.