all right so check this out I have my app running on two separate simulators so basically on two separate devices here and on this device I am logged in as Rob so if you come over here you can see Rob here now on this device I logged in as mic here okay and so I can send a message uh from this device to this device and something interesting is going to happen so if I click here and I say let's say what's up Mike okay I send a message and that message is going going and
what do we see what's up Mike so I can dismiss this I can come over here and I should see this message here what's up Mike and I can send a message here right so I'm chatting with Rob and I can say hey Rob what are you doing tonight send a message here and guess what happens hey Rob what are you doing tonight okay and if we take a look at the chat you can see the last message you can come over here and you can open this sub and you can send another message uh
not sure sure yet maybe watch the game okay send a message here and there's the message and there you see the message and you can see it says notifications from super base and that's very important because these apps are using push notifications and we are doing it exclusively with super base and in today's video I'm going to be showing you how you can build amazing functional very very practical apps with push notifications use using superbase instead of Firebase now before we get started as always all the apps and all the resources that I demonstrate on
this channel are going to be available to view and or clone from my patreon page and if you're still not yet a member for our amazing rapidly growing patreon Community then you should definitely check it out and perhaps consider joining and you can learn more about it via the link in the description below the video now if we jump into our super base uh dashboard here and I click on notifications you will see that we actually have notifications here that are sent out to various users so as you can see hey Rob hey Mike what's
up Mike hey Rob what are you doing tonight etc etc and these here are eventually sent out as notifications and so we are using superbase 100% we're not using Firebase for notifications we are using firebases messaging for notification but this whole app integration is done with super base now let's talk about how you can do the same okay so by the end of the video you will know exactly what you need to do in order to have your push notifications work with superbase Okay so the first thing that you need to do this is very
very important is you need to head over to superbase docs and you need to search for push notifications okay and you're going to be on this document here here and you need to follow the instructions here now initially you want to pick this Firebase Cloud messaging because we are using Firebase Cloud messaging under the hood that is what we're going to be using and you want to follow the instructions here they're really really good instructions they um you know I've done this multiple times I never had any issues and the purpose of this exercise here
is to get your super base working with push notification essentially getting your super base to send push notifications for you so essentially what's going to happen is you are going to have a table called notifications and when you create a record so if you do an insert in that table you're going to have this flow right you're going to trigger something on insert and what you're going to be triggering essentially is going to be an edge function that will be sending push notifications by connecting to fire bases Cloud messaging and in order to have this
flow you need to follow uh all the steps in this document okay and that's pretty much half the battle okay that's half the battle getting it to work because when you set this up what's going to happen here is you're going to have this notifications table and this profiles table and the purpose of this profiles table is to link a user to a uh a token to a messaging token so as you can see we have here two users that I was using to log into the apps and these are the user IDs and so
if I double click here you can see that that's going to go ahead and link us to the original users table that shows the original user um the user record right so this thing is 1D and if we take a look this 1D this is this Rob right so one of the users is Rob the other one is mik and the purpose of disable profiles here and this is a table that you're going to set up uh you know by following the instructions on superbas side that I showed you is to link users to a
token because when you're doing push notifications uh you're not you know you you're not going to be remembering all these tokens that are assigned to every app instance okay so if you have like five apps running whether it's you running them like I was running them myself or like multiple people running them right so maybe you have a friend that's using the app you have a a customer etc etc each app instance is going to have their own token and so instead of you needing to you know memorize these tokens you have a mapping all
right so this user here has this token this user here has this token okay so you're going to have these two tables and the second table that you're going to set up through the process of following those instructions and kind of kind of going going over the checklist going through that checklist is this notifications table okay and so this is the table where if you create a new record and you're going to be pointing it to a user ID it's going to look up the token and it's going to follow this flow here right so
it's you you ENT you create a new record it looks up the actual token it triggers it and then the trigger triggers this Edge function okay this is what you're going to have after you follow the um the instructions on this page okay so once you have all of that done the next stage is you need to get your flter Flow app ready and kind of configured for push notifications and remember guys if you're using Firebase right so if I click on push notifications you see I don't have this enabled because if I enable it
then I need to configure Firebase authentication and because we're using superbase I have superbase authentication enabled and so so if I come over here if I go to authentication you see I have super base enabled right and so if you want to be using super base including super base authentication and everything having to do with super base you're not going to be an uh turning this on right you're not going to be turning this on instead what you're going to be doing is you're going to create a custom action called initialized messaging and this is
the code here and essentially what you're going to be doing is you're going to be manually registering this device uh onto the uh Firebase Cloud messaging Network okay and all of this is done for you by flutter flow if you're using uh Firebase but because we're using superbase this is something we need to do and and thankfully it's just a couple of lines of code so here I'm saying Firebase messaging instance I'm requesting permission I'm requesting permission to receive push notification this is something you have to do once uh per app instance okay so once
you do it for that app you know if you don't delete the app you know it's never going to request it again you know it's it's it's always going to be the same if you delete the app if the user deletes the app then they're going to see that message again like you know do do you allow this app to receive post notifications or something like that once we get permission we are grabbing this token here okay and that token is going to be available right so when you launch the app and you have permissions
you're going to be getting this token okay and now we have this token and so if we are running this app here and if I get out and if I come over here I'm displaying this token here okay I'm displaying this token here and this token is going to be different then you know it's going to be different these tokens are going to be different across devices right so if I come over here you can see that this user has a slightly different token right this is the user ID and this is their token ID
and and this Tok token is is is basically an identifier by where by by by which um Firebase Cloud messaging can find these devices and send uh these notifications okay so this is something you have to do okay so at this point you should have this token I'm basically saving it in App State so we can display it in in um on the profile page as a debug message just to make sure I have that token because once we have that token that's it we're we're in the game right we we we are in the
game we can receive push notifications okay the next thing that I'm doing is I'm using this um this package called awesome notifications in order to display this notification now remember guys whether you're using Firebase or super base while the app is running and it's getting push notification right it's receiving or it has received the push notification it's not going to be displaying it okay that is the case in both scenarios and so if you want to display to the user you have to do it manually okay so even if you're using like you know a
flut flows builtin right with far you enable it it's still not going to display right you have to do this and I'm using this awesome uh awesome package called awesome notification I'm basically initializing here and then what I'm doing here is I have this on uh on message listen right and this is a essentially a call back right this function here gets called when a message is being sent and this call back I'm just saying you know received message and I I'm displaying this create notification that is why you you see these cool uh notifications
right when the when the the push notification has arrived you see these cool dialogue boxes there right so if you're chatting you're going to be seeing that all of that is courtesy of uh this amazing um amazing package here so once you have this thing set up as a custom action the next thing you need to do is you need to go into main. Dart and you need to add it now I like to I like to add it as a final action you can also add it as an initial action here right so all
you need to do is click here select it so if I delete it I click here and I just select it right so I have my custom action here I like to do it as a final action after everything else has been initialized right so it's initializing a bunch of other things and then it's it's calling my um my uh custom code right this custom action now once you have this code here there's one more thing that you have to do right so what you need to do is you need to come in here and
you need to click on permissions and for notifications I have this turned on very very important send notifications I believe if you are using the buil-in flut oflow push notifications with fireb I believe it automatically turns it on for you okay I don't remember but I believe it does that but in any case you have to make sure that you enable it okay because this tells the system that you know we we we we want to take advantage of of this specific functionality now there's one more thing that you need to do after you've configured
uh all your backend stuff when it comes to push notifications is you need to make sure that when you get that token that that token is here is there's a record mapped to a username right very very important because if you get the token but you don't have a record in this profiles table you won't be able to send push notifications okay because it won't be able to do the correct mapping and so if we go to our app here uh in this homepage right so this chats is my homepage I have this top level
action okay and so if you click over here you click here you can open this up and I have one call here and so what I'm doing here is I'm inserting a row into this profile stable okay so when the app loads and remember we got the token before right so we got the token even before the app the app has loaded the pages right that's part of the uh the main app initialization so we've gotten the token then we open up the app we load up the app and the first thing that we're doing
is we have the ID right so the user has authenticated and we have the token we create a record so if you come over here I I'm doing an insert row and I'm doing this authenticated user here and I'm doing this fcm token here okay this is very very important now there's very very important thing that you need to know okay because if your app keeps starting up and it's the same user you're going to have lots and lots of Records here and you do not want to create another record if it's the same thing
right so if it's the same user and the same token there's no need to create another record and so instead of me doing it here and creating all these checks there's a very clever way of doing it in super base and that is where you can create a unique constraint based on either one column or multiple columns in this case I have a unique constraint on two columns and this means that if this is the same as this and this is the same as this basically we have another column that's going to be an exact
duplicate of existing columns it's not going to insert it right so if you come to our table definition here you can see this constraint here and this is very very powerful because it saves me you know a lot of checks and just you know I don't need to check in my code do we have that record already do we have that row already and so as you can see I have this constraint here okay this is the name of this constraint it's Unique on these two fields and in order to create it you can simply
go to SQL editor and just ask superbase AI query to do it you can just say hey uh create me a constraint on these two fields and it's going to generate the code you can just run it okay and so this is is going to make sure that you will never uh be able to add another record if it has the exact same fields of other records we have a two field constraint and so you know if the user logs in so this user logs in they have the same token it's not going to allow
a new row to be inserted and that's fine that's exactly what we want because we don't want to fill it up with like thousands and thousands of rows or hundreds of rows anytime the user logs in and they have the same token from fcm from Firebase Cloud messaging okay so that's the three things that you need to do right so remember this this thing here for sending push notifications then the next thing you need to do is you need to set up this thing for receiving push notifications and then you need to create a uh
a um unique uh Fields constraint essentially on this table here okay so once you do that you're pretty much good to go so now you can build without your app okay so let's talk about this app here so this app here has two t two uh two pages here right so we have the chats and the chat messages and if we head over to our super base here are the three tables that we're using right so this is the chat and I have here the two users that are chatting I have their two user names
right so this is nice for quickly looking up a chat if you want to display to the user cuz we might have you know hundreds of chats but if i l in I just want to show the chats that I'm a member of right so by keeping these as an array it makes it easy to look them up as I'm going to show you in a second and then I'm storing the last message on this chat so that I can display it to the user now the second table is this chat messages and it's kind
of self-explanatory we are essentially storing messages and we have the chat ID the user who is the user that sent the message and the actual message okay so just three Fields here and last but not least we have this users info which is an extension of uh users right and here's where you want to have additional fields that you want to link to users and what I'm doing here is I am essentially I just have another field called username that I am you know just storing on a user level and this is a classical onetoone
relationship and the reason I want to have a username is you know just the play it uh in the app right so if we go to the app you can come over here uh you're going to see that we have you know we're using it all the time so here's the username here and if I click on this it says chat with mic and I'm just I'm using the username cuz you know like an email or something else just would have looked really weird and so I have this username here okay and that's the only
tables that I'm using just three tables along with these notifications and profiles for sending push notifications all right so let's show uh back into flut oflow let me show you the meat of the app now in this list view here we are displaying all the chats but we're also filtering them by a specific condition so remember we have there a field called users that contains a list of usern names that are um that that are part of the chat that are that are chatting with each other and so this users I'm checking for this username
right so this username is this Z users info and what is z users info well it's this this user right here so if you come over here I'm basically opening up my um o this is this o user and I have another query to get the username right cuz usern name is on another table so I just have another query and now you know this the the results of this query are available on this full page so I know the username of the logged in user so if I'm logged in and my username is like
James 2000 or whatever that is what that is what is going to be in this query here and that way I can check to make sure that in these chats here that you know James 2000 is one of these users here and that is exactly what's happening here okay and next I have this code expression here that actually is really Nifty because what we need this code expression for is we need to display the other user all right so we have two users but one of them is me and I don't want to display myself
I want to display the other user right so that way in the app if I come over here we're showing the other users so you know you're going to have two users you know James and Mike 2000 if I'm logged in as James I don't want to show James I want to show my 2000 right so this code expression does that right basically compares the authenticated user to the first record in that list right to the first item in that list if they're the same show me the other item if they're not the same show
me the first item right that's all it's doing we're displaying the last message and when we click on this right we redirecting to chat messages and I'm I'm I'm sending in the chat record I'm sending it the other person and I'm sending in the other person ID because that's going to be useful on this page here on this chat messages right because we want to display it here and here I have a condition I'm basically saying other person is set then say chat with the other person however if this is a new chat we haven't
saved it yet I'm just saying new chat okay very very simple and here's our normal flow that I've done many many times so if you've seen my previous videos you know exactly how this flow works I just have basically a query where I am listing all the chat messages for a specific chat ID right cuz if we come over here we have these chat messages we have this chat ID right so in this case these are all messages that are part of the same chat ID but you're going to have you know hundreds or thousands
tens of thousands of messages with different chat IDs and you don't want to list all the messages right that's a security issue you want to uh filter it by this ID and this is that chat uh row that we passed and then depending on you know if this is my message or the other message we are going to be either displaying the other message on the left left Justified or my message right Justified which is kind kind of how you know chat apps work and so you're not you're never going to have two messages on
the same row you're going to have a row here maybe a message here another row here maybe a message here or multiple rows Within you know message you're never going to have two messages right cuz you're either going to be left Justified or right Justified and here's where you enter new message and then we have the send message flow open this up and here we are seeing a couple of things so the first thing we're doing is we're creating a record in chat messages chat ID user ID and message we are also updating the role
right so we're updating the last message on the the chats uh the chat screen right so that you can see that last message here so if I come over here I can see this last message here okay on the main on the main page here so we're doing that here next we are sending the push notification okay and we do that by uh adding a record inserting a record in this notifications table and here we're putting in the user ID which is the other person ID right because we don't want to send it to ourselves
we want to send it to the other user and then the body is the message the input message right and so this is the Sending message flow and this is going to be configured once you follow instructions on all that where where you know if you create a new record you uh trigger in an edge function that goes ahead and sends this uh push notification and last but not least we basically clear the input field so that we don't need to uh you know erase the message delete the message here we can start typing uh
again with a cleared input field that's pretty much it right so the chat up I've done before uh pretty standard right and obviously if you're going to be a member of our amazing patreon Community you're going to get access to all of this very uh very easily so that you can clone and kind of Tinker with it but the main thing that I wanted to show you guys is the push notifications right so you're going to configure your send you're going to configure your receiving end and you're going to also work on your um make
sure that you have that uh constraint so that you know you there's you won't be able to create a new role if the fields are the same as any of the previous R really awesome feature that you know one of one of the many many reasons why I love using super base for all kinds of projects and speaking of projects the best way to kind of work on a similar project or whether you want to build a a more complex app or you know you want to build a a similar app or you just want
to you know Implement push notifications in one of your other apps maybe it's not even a chat app maybe it's a it's an app in a completely different Niche well the best way to do that is by viewing and or cloning this app and you will be able to do just that when you join our amazing patreon community and remember when you join our amazing patreon Community you're going to get access to a ton of things I mean there's so many people on there there's you know so much resources so much content on there so
you're going to get access to this app you're going to get access to pretty much all my apps that I uh you know buil tutorial around kind of published on this channel there I think more than 160 apps so far on there and that's not all you're going to you're also going to get access to other uh amazing content such as q&as live streams behind the scenes content and my patreon supported Master Class series and these are essentially tutorials that go above and beyond the stuff that I have on YouTube and so I think one
of the next ones that we're going to be doing is going to be about push notifications and so if you're serious about no code you're serious about building apps or you just want to support this channel then you definitely need to need to become a member of our amazing patreon Community because when you do that you're going to get access to a ton of things and you're going to be a part of this incredible incredible Community where everybody's kind of helping each other to kind of uh get over various challenges and figure out how things
work we we truly have an amazing community and if you're serious about no C then you're going to love being a part of this amazing amazing community so if all of that sounds like something that you may be interested in something that you're going to get value out of then I seriously encourage you to check it out and consider becoming a member and you can do just that via the link in the description below the video