BACK

shopify force a user to enter a username and password before showing products

Require Login to Access Shopify Store hey scott austin here from jade puma in,this video i'm going t

JadePuma

Updated on Mar 01,2023

Require Login to Access Shopify Store

The above is a brief introduction to shopify force a user to enter a username and password before showing products

Let's move on to the first section of shopify force a user to enter a username and password before showing products

Let TThunt's experts help you find the best TikTok product on your Shopify business!

Find TikTok products (It's Free)
No difficulty
No complicated process
Find winning products
3.5K Ratings

WHY YOU SHOULD CHOOSE TTHUNT

TThunt has the world's largest selection of TikTok products to choose from, and each product has a large number of advertising materials, so you can choose advertising materials for TikTok ads or Facebook ads without any hassle.

shopify force a user to enter a username and password before showing products catalogs

Require Login to Access Shopify Store

hey scott austin here from jade puma in,this video i'm going to show you how to,make an entire shopify store require a,login this is actually a really easy,thing to do,with just liquid code you don't need an,app or anything all there are apps that,do this but if you're comfortable just,copying pasting 10 lines of code you can,do this in your store without an app,so let me show you what how this behaves,right so here you see,i'm on a website this is actually a,wholesale website i'm working on for a,client,and if i click on any link,you'll see that i keep getting the,wholesale portal login page which is,under the url of account forward slash,login this is a standard page in every,shopify store,um,but regardless of what page i click on,it still takes me back to this this,wholesale login page and that's because,i'm not logged in and i can see that,here because my,login icon it says login instead of you,know account,so if i log in,using a username and password that's,valid in shopify now all of a sudden i'm,in you know the store and i can click on,any of the pages and browse the store,normally and you can see now my my,little login icon says account which,means i'm logged in,so let's just go in and log out again,and show you how this works right,so in in the code i'm going to shopify,admin for this store i'm going to go,under online store,and under,themes,then actions then edit code,and i'm going to open up the,theme.liquid file,which is stored right up here in layout,under theme.liquid and it's already open,and the code that makes this happen is,just these 10 lines of code,um so what you know explain the logic of,what this code is doing um and i'll,include a,little snippet of this code on the the,page that on my blog on my website where,you can copy and paste the code you,might have to change it a little bit for,your situation,but this will get you started and right,down the right path,so what we're doing here is we're,basically,in in this logic here we're asking,ourselves do we want to redirect the,customer,to um the login page so you see the,first thing is an unless statement um in,less customer and think of customer as,logged in right if if you ask in in,liquid if customer it actually looks are,is this user on the website logged in or,not,so basically we're saying,if you know unless customers if not,logged in,so if they're not logged in then,continue looking right,so if they're already logged in this,next set of logic gets ignored and then,what we look at is if template contains,customers,and this,is you know if you haven't played with,liquid code a little bit this is one of,the more um you know things you have to,learn right it's one of those learnings,you do because normally the template,is you know usually in the file name of,uh,let's just look at a template here's the,article template for example right,um it just says article.liquid,the the deceiving thing is or the little,trick you have to learn is,there's a subfolder in templates and,that's what these are customers cut,account customers activate account,customers addresses,and log in and order so there's a whole,bunch of customer type pages,that are in a sub folder called,customers,so this,login page even though up here it just,says account login the template name,actually contains the phrase customers,because that login,right here this,login.liquid is in the subfolder,customers so basically what we're saying,here is,if they're already on one of these,customer pages like the login page then,you know we're not going to redirect,them because if they're already on this,login page we don't want to redirect,them to the login page would end up,being an infinite loop,and then what we say is you know,if so if it's false if if they're not on,one of these customer pages and they're,not logged in as a customer,then we're going to set a variable send,a login equals true all right so send a,login going through this loop it's,either going to be false or it's going,to be true and don't forget if they're,already logged in,send to login we're not setting it,anywhere so it will be false by default,and then once we go through that little,logic there,then we have a simple if then statement,if send a login right so,this is,basically,saying if we've already set this to true,up here and so there's two if statements,right if send send to login which,basically is if we've already set it to,true,and request path is not challenge,so that's when you know they're,authenticating and stuff like that um,and that's i think that's the uh the,forget your password page,so,if,they're not logged in as we're figuring,out here they're not on a customer page,um and they're not on the challenge page,then what we're gonna do is we're going,to redirect them to,a new page and that's what this is html,this isn't liquid this line here this is,html and it's just a meta and it says,content right send them to this url,which is account login and every store,has a forward slash account for slash,login page in shopify,it also says then go refresh the page so,all this other content below,um actually is is not used because the,first thing it shows up but then you,know,the site listens to this first command,which says redirect them to the account,login page and that's what you see,happening here is as i'm not logged in,right now i click on any one of these,and,i and if you look up here in the url,string you'll see it goes to that page,for a second right if i click on your,rig,i saw it said collection something there,a second ago and then it got redirected,so it quickly loads the page and the,first command it sees is redirect to the,login page right so that that's what's,happening there,um,and so that's that's the code it's as,simple as this to add you know these 10,lines to your theme liquid right,underneath the head so it's the first,thing that happens on every page on your,site,um when it loads up it goes through,those different rules determines if,we're gonna redirect it to the login,page or not and then performs that,action,now something to think about is,in your login page,and then this will depend on the,business rules for your store for,example this store here is a wholesale,store and it's a whole it's a wholesale,store it's standalone from the retail,store,so,we've made the entire site require login,and if they want to apply for a,wholesale account they've got to do that,on a form that we put on the retail,store so looking for apex chassis retail,store click here for our consumers,you know,click here for our consumer store and we,also have a link up here that says if,you want to apply for a wholesale,account apply here if i click on that it,takes me over to the retail store and,then the the apply,application form shows up for them,so,and what we did you know most people,don't edit their account login page,right so what you're probably going to,want to do is edit your account login,page to put some extra verbiage around,what's going on like hey you know,welcome to our wholesale portal you must,you know log in with your wholesale,account,and any other directions what i also did,on this one is because the application,is not just create an account in shopify,through the shopify account creation,process which actually apply and the,store staff evaluates your application,and then approves it and what they do,once it's approved they manually add,that,customer information,into the shopify store and send an,account invite out so you'll notice on,this account page there's no,sign up link and there was in this,account most account pages by default,have a don't have an account click here,to sign up so based on your business,rules you may want to you know comment,that out and not allow them to create,their own accounts if you want them to,go through a separate application,process,so that's how we get an entire site to,require login just editing uh you know,the theme dot liquid with a little bit,of code that redirects everybody that is,not logged in to the account login page,and then we optimize our account login,based on our business rules,of you know whether we allow them to,sign up for accounts here or have to go,through a process to do it so hopefully,that was helpful thanks

Congratulation! You bave finally finished reading shopify force a user to enter a username and password before showing products and believe you bave enougb understending shopify force a user to enter a username and password before showing products

Come on and read the rest of the article!

Browse More Content