How do I know if the my app has been installed?

Highlighted
Shopify Partner
1 0 1

I'm working on my first public Shopify App and I'm stuck...

I've impletmented OAuth, but I'm not sure how I'm supposed to know if the user has installed the app or not when I recieve a request. Right now, I'm storing the user's token and shop URL in MySQL. Upon recieving a request, I'm checking to see if an entry for the shop URL exists, if it does I redirect to the main app page. If the record doesn't exist, I'm starting the OAuth process.

The problem with that is that I don't know when a user uninstalls the app, so when the user clicks on the install button after an uninstall, I still think the app is installed, so I'm displaying the app page. 

It seems like I should be able to give Shopify a seperate install URL and store URL in the app setup, but I don't see anything like that. Am I missing somthing? What process does everyone else usually use?

1 Like
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
531 0 97

Hey Craig,

You should be able to register a webhook for "apps/uninstalled." Then, whenever a store owner uninstalls your app you'll get a webhook and you can take the appropriate action.

Cheers,

Jamie

1 Like
Highlighted
Shopify Partner
3 0 1
ActiveResource::UnauthorizedAccess Exception: Failed.  Response code = 401.  Response message = Unauthorized

I tried app/uninstalled webhook, but for everything, I am facing this issue. I created a tag using Shopify API via my app, now how can I remove the tag when the merchant uninstalls my app?

0 Likes
Highlighted
Shopify Partner
30 0 1

Hi,

Can you please explain how you did the following: 

 

"Upon recieving a request, I'm checking to see if an entry for the shop URL exists, if it does I redirect to the main app page. If the record doesn't exist, I'm starting the OAuth process."

 

 

im trying to do this on my app but it always starts the OAuth process eventhough the entry exists in my database. My code looks something like this:

 

				request.query("select * from table_name where shop_name = '" + shop + "'", (err, recordset) => {	
					if (err){
						console.log(err)
					} 	else{
						if(recordset.recordset.length > 0){
								ctx.cookies.set('shopOrigin', shop, {
								httpOnly: false,
								secure: true,
								sameSite: 'none'
							});
								 ctx.redirect("https://" & shop & "/admin/apps/my_app")
								 return true;
						}else{
								
								console.log("not installed")
						}
						
					}            
				});

as you see im redirecting to the app but for some reason it still does the OAuth process and another entry gets added....do you know what im doing wrong?

 

0 Likes