Clerk vs Next-Auth.js | It's not that simple...

Jan Marshal
8 Dec 202311:30

Summary

TLDRThis video explores the decision-making process for implementing authentication in a SaaS application. It weighs the pros and cons of using a hosted provider like Clerk or Auth0 versus a self-hosted solution like Next.js Auth. The choice depends on the business model and user base: for simple B2C applications with few paying users, Next.js Auth is recommended to avoid high costs. However, for B2B applications with enterprise customers, a hosted provider is preferable due to the advanced features and reduced development time. The video also addresses the potential risks and costs associated with changing pricing models and the complexities of building and maintaining a custom authentication layer.

Takeaways

  • 🤔 The choice between using a hosted SaaS provider for authentication or building your own with a library like Next.js is not straightforward and depends on the specific use case and business model.
  • 🔒 For simple applications requiring basic authentication, using an open-source, self-hosted solution like Next.js is recommended to avoid the costs associated with hosted providers.
  • 💰 Hosted providers like Clerk or Auth0 can be cost-prohibitive for applications where not all users pay for the service, as their pricing can be high and may not provide enough return on investment.
  • 🏢 For B2B SaaS applications with enterprise customers, a hosted provider is often preferable due to the need for advanced features like SSO, MFA, and robust organization management that may be time-consuming or complex to build from scratch.
  • 🛠 Building your own authentication layer with Next.js can be time-consuming, requiring the development of user interfaces, error handling, and complex logic that comes pre-built with hosted solutions.
  • ⏱️ Implementing authentication with a hosted provider can be significantly faster, potentially taking as little as 15-20 minutes, compared to the hours or more required for a custom solution.
  • 💡 The decision to use a hosted provider or build your own should consider the potential savings in development time and the costs associated with maintaining a custom solution.
  • 📈 For B2B applications where most users are paying customers, the small fees charged by hosted providers may be negligible compared to the value they bring in terms of features and ease of use.
  • 📊 The potential for unexpected price increases from hosted providers is a risk, and businesses should consider the impact of such changes on their cost structure.
  • 🛑 If a hosted provider significantly raises their prices, businesses may need to consider migrating to a different provider or building their own solution, which involves a significant investment of time and resources.
  • 📝 Compliance with regulations like GDPR is a consideration for both hosted and self-hosted solutions, and businesses must ensure they can meet these requirements regardless of the authentication method chosen.

Q & A

  • What is the main topic discussed in the video script?

    -The main topic discussed in the video script is the decision-making process for choosing between using a hosted SaaS authentication provider or building your own authentication system using a library like NextAuth for a SaaS application.

  • What are the two options presented for implementing authentication in a SaaS application?

    -The two options presented are using a hosted SaaS provider like Clerk or Auth0, or building your own authentication using an open-source library like NextAuth.

  • What factors should be considered when choosing between a hosted provider or building your own authentication system?

    -Factors to consider include the complexity of the application, the business model (B2B vs B2C), the need for advanced features like SSO and MFA, the cost of the hosted service, and the potential for scalability and maintenance.

  • Why might a simple application with basic authentication needs be better off using NextAuth instead of a hosted provider?

    -A simple application might benefit from using NextAuth because the cost of a hosted provider could be disproportionately high compared to the revenue generated by users, especially if not all users are paying customers.

  • What are some of the advanced features that might be needed for a B2B SaaS application?

    -Advanced features for a B2B SaaS application might include Single Sign-On (SSO), Multi-Factor Authentication (MFA), and a robust organization layer for managing different user roles within an enterprise.

  • What is the potential downside of using a hosted authentication provider for a B2B SaaS application?

    -The potential downside is the cost associated with using a hosted provider, which can increase significantly if the pricing model changes, and the time and effort required to migrate to a different provider or build your own system if needed.

  • Why is building your own authentication layer time-consuming and complex?

    -Building your own authentication layer is time-consuming and complex because it requires developing and maintaining custom UI elements, handling form errors, implementing security measures, and ensuring compliance with regulations like GDPR.

  • What are some of the benefits of using a hosted authentication provider like Clerk or Auth0?

    -Benefits include ease of implementation, automatic error handling, built-in security features, and the ability to quickly add advanced authentication features without extensive development work.

  • What is the importance of considering the cost per user when deciding between a hosted provider and building your own authentication system?

    -The cost per user is important because it helps determine if the investment in a hosted provider is justified by the revenue generated by each user. It's a key factor in calculating the return on investment for the authentication solution.

  • How does the script suggest approaching the decision if a hosted provider significantly increases its prices?

    -The script suggests considering migration to a different provider or building your own authentication system if the price increase is substantial and affects the business's bottom line.

  • What is the script's final recommendation for a B2B SaaS application where most users are paying customers?

    -The script recommends using a hosted provider for a B2B SaaS application with paying customers, as the benefits in terms of time saved, ease of use, and advanced features usually outweigh the costs.

Outlines

00:00

🤔 Choosing Between Hosted and Self-Hosted Auth Solutions

This paragraph discusses the dilemma of selecting between a hosted or self-hosted authentication solution for a SAS application. It highlights that the decision is not straightforward and depends on various factors such as the business's use case, state, and application structure. The speaker suggests using Next.js for simple applications requiring basic authentication, as it avoids the costs associated with hosted providers like Clerk or Auth0. However, for B2B applications with enterprise customers, the paragraph leans towards using a hosted provider due to the need for advanced features like SSO and organization management, which are more complex to implement with self-hosted solutions.

05:01

🛠 Building vs. Using Hosted Auth for Complex Applications

The second paragraph delves into the complexities of building your own authentication layer versus using a hosted solution. It emphasizes the time-consuming and resource-intensive nature of creating custom UIs, handling form errors, and managing authentication logic with self-hosted options like Next.js. In contrast, hosted solutions such as Clerk, Auth0, and others offer ready-made sign-up pages and automatic error handling, significantly reducing the development time and effort. The speaker also touches on the potential risks of relying on hosted providers, such as sudden price increases, and the challenges of migrating to an alternative provider or building a custom solution from scratch.

10:03

💡 Deciding Factors for Auth Solution Based on Business Model

The final paragraph wraps up the discussion by summarizing the key considerations for choosing an authentication solution based on the business model. For B2C applications where not all users contribute revenue, Next.js is recommended for its simplicity and cost-effectiveness. Conversely, for B2B applications where users are likely to pay for the service, the paragraph advocates for hosted solutions despite the associated costs, due to the time and effort saved in development and maintenance. The speaker shares personal experience, noting the challenges of scaling a self-hosted authentication layer and the potential compliance issues that may arise with enterprise-level applications.

Mindmap

Keywords

💡SaaS application

A Software as a Service (SaaS) application refers to a software application that is delivered over the internet as a service. In the context of the video, the speaker is discussing the implementation of authentication for a SaaS application, which is a critical component for user access and security.

💡Hosted SaaS provider

A hosted SaaS provider is a service that offers SaaS applications over the internet. Examples given in the script include Clerk and Auth0. The speaker compares these to self-hosted solutions, discussing the pros and cons of using a third-party for authentication services in a SaaS model.

💡Next.js Auth

Next.js Auth is an open-source library used for implementing authentication in Next.js applications. The script mentions it as an alternative to hosted providers, suggesting that for simple applications, Next.js Auth might be a more cost-effective solution due to its self-hosted nature.

💡Basic authentication

Basic authentication is a simple method of identifying users by requiring a username and password, often used in conjunction with social logins like GitHub, as mentioned in the script. It is the most straightforward form of authentication and is suitable for applications with minimal security requirements.

💡SSO (Single Sign-On)

SSO is an authentication process that allows a user to access multiple applications with one set of login credentials. The script discusses the necessity of SSO for enterprise customers, indicating that hosted providers like Clerk or Auth0 offer this feature, which may not be as easily implemented with self-hosted solutions.

💡Enterprise customers

Enterprise customers are businesses or organizations that purchase products or services for use within their company. The video script emphasizes that for B2B SaaS applications with enterprise customers, using a hosted SaaS provider is recommended due to the need for advanced features like SSO and robust authorization systems.

💡Authorization

Authorization is the process of giving users permission to access certain resources or perform certain actions within a system. The script explains that for complex applications, especially those serving enterprise customers, a good authorization layer is crucial, and this can be more efficiently provided by hosted providers.

💡Multi-factor authentication (MFA)

MFA is a security method that requires more than one method of authentication from independent categories of credentials to verify the user's identity for a login or other transaction. The script suggests that implementing MFA can be complex with self-hosted solutions like Next.js Auth, and it might be more practical to use hosted providers for this feature.

💡B2B SaaS

B2B SaaS stands for Business-to-Business Software as a Service. The script discusses that for B2B applications, where customers are other businesses, the use of a hosted provider might be more beneficial due to the need for features like SSO, MFA, and advanced authorization that these businesses expect.

💡Cost

In the context of the script, cost refers to the expenses associated with using either a hosted SaaS provider or building and maintaining a self-hosted authentication system. The speaker discusses how the cost can be a determining factor in choosing between these options, especially considering the potential for high prices or unexpected price increases from hosted providers.

💡Regulation compliance

Regulation compliance refers to the adherence to laws and regulations, such as GDPR for data protection. The script mentions that building your own authentication layer with Next.js Auth requires ensuring compliance with such regulations, which can be a complex and time-consuming task, suggesting that hosted providers may offer a more straightforward path to compliance.

Highlights

When building a SAS application, the choice between a hosted SAS provider or a self-hosted solution like Next.js depends on the specific use case and business state.

For simple applications requiring basic authentication, using an open-source solution like Next.js is recommended over hosted providers due to cost-effectiveness.

Hosted providers such as Clerk or Auth0 may incur high costs that are not justified if not all users are paying for the service.

For B2B SaaS applications with enterprise customers, a hosted provider is advised to access advanced features like SSO and organization management.

Building your own authentication layer with Next.js can be time-consuming and complex, especially when compared to the ease of using hosted services.

Hosted services like Clerk or Auth0 provide ready-to-use features such as sign-up pages, error handling, and connection to authentication methods.

The decision to use a hosted provider should consider the potential cost implications and the value of time saved in development.

Enterprise customers expect a robust authentication system, which might be challenging to build and maintain with self-hosted solutions.

The potential for sudden price increases with hosted providers presents a risk that businesses need to evaluate.

Migration from one provider to another or building a custom solution can be a difficult decision, especially after significant price hikes.

The need for compliance with regulations like GDPR adds another layer of complexity to self-hosted authentication solutions.

B2C applications where most users do not pay for the service may benefit from the simplicity and lower costs of Next.js.

B2B applications with paying users can justify the use of hosted providers for the convenience and advanced features they offer.

The trade-off between saving on authentication costs and investing time and resources into building a custom solution must be carefully weighed.

Maintenance and error handling are ongoing considerations for businesses that choose to implement their own authentication layer.

The speaker's personal experience suggests that building a custom authentication layer for a growing business can be challenging and not as fun as expected.

The video aims to help viewers understand the pros and cons of both hosted and self-hosted authentication options to make an informed decision.

Transcripts

play00:02

so let's imagine the following you're in

play00:04

the position where you are building

play00:05

currently a SAS application and now

play00:08

you're at the step where you have to

play00:09

implement off and now you have two

play00:11

options either use a hosted um SAS

play00:14

provider like for example Clerk or off

play00:16

zero or work Os or you roll your own off

play00:20

using a library like next off and now

play00:23

the question comes which one should you

play00:24

use and it's not an easy question to

play00:27

answer since both um providers or both

play00:30

options in that sense have Pros cons

play00:33

caveats or you could say the answer is a

play00:35

double-sided knife because there's no

play00:37

white or wrong answer it depends on your

play00:40

use case on your business State um how

play00:42

your application is built Etc but after

play00:45

this video you'll actually understand

play00:46

what option is the right one for which

play00:49

business use case so now let's roll the

play00:52

video so let's talk about the use case

play00:55

first of all so let's say you're

play00:56

building a very simple application where

play00:59

all you need is basic authentication

play01:01

that means o off using for example

play01:03

GitHub and then maybe also magic links

play01:06

something like that and now what should

play01:09

you use in that case so it's very simple

play01:11

you don't need no account linking

play01:13

Enterprise off um organizations you

play01:15

don't need it all you need is basic off

play01:18

and then I guess uh authorization using

play01:20

your database um in that case you should

play01:23

actually use next off forget about

play01:26

anything that's hosted so in that sense

play01:28

Clerk or zero work OS OCTA whatever you

play01:32

uh know don't use it use next off use

play01:34

something open source and uh selfhosted

play01:37

why is that because if you're building

play01:40

something so simple there's a pretty

play01:43

high probability that not every user

play01:45

that you onboard pays for your service

play01:47

because if it's that case that where you

play01:49

have for example 10,000 users and from

play01:52

those 10,000 users maybe 10 50 100

play01:56

people only pay for your service I would

play01:59

actually say it's not uh very good to

play02:01

use an hosted provider why is that well

play02:04

an hosted provider like Clerk of zero or

play02:06

work OS has of course a cost behind it

play02:09

you pay to use the services which is

play02:12

normal right and the problem is that

play02:14

these prices can be quite high so if you

play02:17

have an application where not every user

play02:19

pays for your service it will be

play02:22

actually not not good expense for you

play02:25

because you pay way too much but get uh

play02:28

not enough in which return for what you

play02:30

pay but now let's take the following you

play02:32

have a B2B SS and you have Enterprise

play02:35

customers so for example you have Google

play02:37

as your own customer imagine that in

play02:40

that case forget next off just forget it

play02:43

uh get it out of your mind forget it in

play02:45

that case I would use a hosted s

play02:47

provider so Clerk of zero or work OS why

play02:51

is that well because you will actually

play02:53

need features that you don't get using

play02:55

next off or which you can get but have

play02:57

to build on your own and which will take

play02:59

a lot of time so if you have Enterprise

play03:02

customers you for example need SSO you

play03:04

can get that using next off but it will

play03:09

be I don't know is it simple it's not

play03:11

quite simple but you can do it but I

play03:14

wouldn't suggest that also if you have

play03:16

uh a B2B SS you'll actually have to need

play03:19

to create organizations think about like

play03:22

that you have a company right company

play03:24

ABC this company has a CEO managing

play03:27

director whatever and then you have Alo

play03:29

the normal in quotations workers which

play03:32

have normal roles right and the same is

play03:34

also for your application if you have a

play03:37

B2B application which is a multi-tenant

play03:39

application for example and you have an

play03:42

organization which you want to onboard

play03:44

to your application you will have to

play03:46

have a pretty good um organization layer

play03:49

on your off layer which means if you're

play03:51

on board a company a organization what

play03:54

you have to do is a good authorization

play03:57

system where the admin the CEO for for

play03:59

example can actually choose other admins

play04:02

and other members so what I mean with

play04:04

that is you need a good authorization

play04:06

layer in that sense um that not every

play04:08

user which is in a organization can do

play04:11

everything so you need for example

play04:13

different roles for different users in

play04:16

your organization you can do that using

play04:18

next off it's doable I uh I did it

play04:22

myself it's fine you can do it I

play04:24

wouldn't do it actually because why

play04:26

should you if you think about it you

play04:28

have a B2B says in most cases that means

play04:31

that every user that comes to your

play04:33

application also pays for your

play04:36

application and if that happens then the

play04:38

question comes why should I even bother

play04:41

building it uh on myself why should I

play04:43

bother implementing MFA so multifactor

play04:46

off which is not uh so easy next off why

play04:49

should I bother uh creating this whole

play04:52

organization layer um uh authorization

play04:55

layer why should I Bor even actually um

play04:58

do everything like that why should I

play05:00

right uh right if every user that comes

play05:03

and pays for my service it would just be

play05:05

much uh simpler another thing is if you

play05:07

actually opt in to use next off and

play05:10

actually build your own off layer the

play05:12

problem is that you actually also have

play05:13

to build U the UI for that so in that

play05:16

sense you have to build the sign up page

play05:18

the login page the forget password page

play05:20

you have to handle form errors uh you

play05:22

have to handle the whole logic you have

play05:24

to do a lot of things to make it work

play05:26

the thing is with Clerk of zero and work

play05:28

OSS is that you actually can use the

play05:31

hosted um sign up pages and the nice

play05:33

thing with that is everything is done

play05:35

for you automatically error handling uh

play05:38

checks for password um this whole

play05:40

connection to O offs and magic links

play05:43

everything is done for you and at the

play05:45

end of the day is if you use for example

play05:48

a hosted application you can make off

play05:50

work in I don't know 15 minutes 20

play05:53

minutes if you're not the fastest which

play05:55

is also fine but if you use the next off

play05:58

as your authentication layer my man you

play06:00

will have to I don't know 12 hours 13 14

play06:03

15 30 50 I don't know um how complex

play06:07

your applications but the more complex

play06:09

your application becomes the harder it

play06:11

becomes uh to achieve this using a open-

play06:14

source authentication layer that means

play06:16

if it's something very simple and you

play06:18

don't need anything uh which is complex

play06:21

then don't bother using next uh uh clerk

play06:24

any your host the provider but if you're

play06:26

looking at actually creating something

play06:28

complex with authorization uh

play06:31

organizations multiactor off SSO I don't

play06:35

know something that you really don't

play06:36

want to build your on your own hey

play06:38

forget next off use something hosted why

play06:41

should you use something uh why should

play06:43

you build it on your uh by yourself if

play06:46

there's something like that but that's

play06:47

if you think about it in a deaf uh mind

play06:50

in a deaf environment I guess but let's

play06:52

say you're a business owner what do you

play06:54

do now because at the end of the day if

play06:56

you use a host provider a host that says

play06:58

like Clerk of zero work OS there's of

play07:01

course a cost associated with it and for

play07:04

example the problem is for example um I

play07:07

think yesterday or the day before I

play07:09

can't quite remember um of zero made a

play07:11

Blog article where they said um that

play07:14

they have changed their pricing to be

play07:16

more accessible or some I don't know

play07:18

marketing stuff like that at the end of

play07:21

the day what they really did is increase

play07:23

your prices by

play07:24

300% again 3 0 Z 3 100% increase imagine

play07:31

you pay $1,000 a month for off zero now

play07:34

you pay $3,000 uh a month just from

play07:37

today to Tomorrow there's such an

play07:40

increase out of nowhere and now imagine

play07:42

you have 10,000 users inside of your off

play07:44

zero database what do you do now do you

play07:47

just say yeah fine okay I will pay this

play07:49

300% increase it is what it is or do you

play07:53

say I migrate off and build all of this

play07:55

nasty uh stuff uh by myself and well

play07:58

that's hard question to answer and I

play08:00

can't answer it for you it's not that

play08:03

simple as said you have two options you

play08:05

either migrate to a different provider

play08:07

like clerk work Os or you go and build

play08:10

it by yourself and now the thing is if

play08:13

you build it by yourself you will have

play08:14

to waste or not waste I guess but you

play08:17

have to take a lot of hours to build

play08:19

what you have using this hosted provider

play08:21

you have to build authorization you have

play08:23

to build um I guess this whole

play08:25

multiactor off if you need it the

play08:27

organization layer you have to build

play08:29

build everything by yourself and it

play08:31

takes a lot of time a lot of uh a lot of

play08:33

money actually because you have to pay

play08:35

your employees for that it's not that

play08:37

simple but let me summarize it like that

play08:40

if you have a B2B application so you

play08:43

have a busines to business application

play08:45

where each user or Mo or let's say

play08:47

almost every user that you on board pays

play08:50

for your service then just pay the fee I

play08:53

mean God what is it 5 Cent 6 Cent per

play08:56

user then just pay it if your user

play08:58

brings in $100 a month and you have to

play09:00

pay I don't know 10 cents a month to

play09:02

your off provider then do it I mean the

play09:05

headache that you will have from

play09:06

building your own off layer or your own

play09:08

Enterprise off layer is way bigger than

play09:12

if you try to use an hosted provider and

play09:14

don't even uh get me started on if you

play09:17

actually become an Enterprise you'll

play09:19

have even more problems using your own

play09:21

off layer why is that because well you

play09:24

have to actually also somehow achieve um

play09:26

certain security risks right or not a

play09:29

aieve them but prevent them and for that

play09:32

you will have to actually get certified

play09:33

etc etc you probably already saw that

play09:35

always if you scroll down to the website

play09:38

there's this whole gdpr or whatever that

play09:40

is uh you have to be compliant to

play09:42

certain regulation and the thing is you

play09:45

can achieve that using next off you can

play09:47

do that that's fine do you want to do

play09:49

that that's the real question do you

play09:51

really want to do that I don't know I

play09:53

wouldn't so what I would say is if your

play09:55

application is basic b2c not every user

play09:58

brings in money or actually most users

play10:00

don't bring any money and all you want

play10:02

is actually just to authorize them then

play10:05

just use next off forget it but let's

play10:08

say you build a B2B s where every user

play10:10

brings in money uh pays to use your

play10:13

service then use clerk I mean really who

play10:16

cares man this 5 cents 6 cents sure you

play10:19

could save them using uh building your

play10:21

own off layer but it's still a

play10:24

double-sided knife because you think oh

play10:26

yeah I can save that much money but in

play10:29

the same case or in that but in the

play10:31

still in the same time you actually have

play10:33

to pay using a different method and

play10:36

that's time building your own off layer

play10:39

takes huge amounts of time you have to

play10:41

actually maintain it you have to handle

play10:43

errors it's not easy so if it's a B2B

play10:46

says use something hosted it will save

play10:49

you a lot of headaches I talk from

play10:51

experience I have tried to build my own

play10:53

authentication layer and scale it to a

play10:56

bigger size it it wasn't fun I was will

play10:59

tell it like that but um if you are

play11:01

bullying something simple forget about

play11:04

Clerk or anything like that but now I

play11:06

hope I could actually help you and try

play11:07

to understand the both options and what

play11:10

pros and cons we have because at the end

play11:12

of the day it's not an easy option to

play11:14

choose and that's also not a right or

play11:16

wrong option it is what it is you choose

play11:18

what you choose and it will have Pros it

play11:20

will have cons um so yeah I hope you

play11:23

enjoyed this video and I hope I will see

play11:25

you on the next video which will drop in

play11:27

a few days so now bye

Rate This

5.0 / 5 (0 votes)

Related Tags
SAS ApplicationAuthenticationSelf-HostedHosted ProviderBusiness Use CaseB2B SaaSEnterprise CustomersSSOMulti-Factor AuthOpen Source