Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple username/password authentication, which method should I use? #745

Closed
zwl1619 opened this issue Jun 24, 2020 · 10 comments · Fixed by #1057 or #1033
Closed

Simple username/password authentication, which method should I use? #745

zwl1619 opened this issue Jun 24, 2020 · 10 comments · Fixed by #1057 or #1033
Projects

Comments

@zwl1619
Copy link

zwl1619 commented Jun 24, 2020

There are 5 authentication providers here: https://redwoodjs.com/docs/authentication
I want to use simple username/password authentication, and save users in my database.
Which one should I use?

@cannikin
Copy link
Member

None of these will save users in your database automatically, you'll need to set that up yourself.

I have a project that uses Netlify Identity for my login and here's how I go about creating a local user in my DB when someone signs in the first time:

// api/src/lib/auth.js

import { AuthenticationError } from '@redwoodjs/api'

import { db } from './db'

export const getCurrentUser = async ({ name, email }) => {
  const user = (await db.user.findOne({ where: { email } })) || (await createUser(name, email))
  return user
}

const createUser = (name, email) => {
  return db.user.create({ data: { name, email } })
}

export const requireAuth = () => {
  if (!context.currentUser) {
    throw new AuthenticationError("You don't have permission to do that.")
  }
}

So I'm getting the name and email out of the JWT that is getting passed to getCurrentUser and trying to lookup a user in my local database using that email address. If it isn't found then I create a new user with the name and email and return that user.

@mojombo
Copy link
Contributor

mojombo commented Jun 24, 2020

@cannikin that would make a nice cookbook recipe doc, I imagine a lot of people wanting to do that exact thing.

@zwl1619
Copy link
Author

zwl1619 commented Jun 25, 2020

in #214 , @DanielKehoe said:

I'm concerned about the financial cost of using Netlify Identity. It's free to add Identity to the Netlify free "Starter" level with a limit of 1000 active users. At the “Pro” level, which costs $45/mo, adding Identity costs $99/month, with a limit of 5,000 active users. Apparently “active users” is the number of users who log into your site during a month. Consider the use case of a gated content website ("sign up with your email address for access to a free tutorial"). Without devolving into a discussion of what is fair pricing or sustainable for various use cases such as SaaS, the model itself (with cost of hosting tied directly to the number of users) would inhibit use of Redwood for some use cases. For sake of comparison, adding Devise to Rails for authentication costs nothing. I hope there's a way to add authentication and authorization to Redwood without restricting the use case to be less than universal.

So , @cannikin Will that save users in Netlify Identity? Will it come with costs?

And, will there be an authentication system that does not rely on third parties?

@cannikin
Copy link
Member

cannikin commented Jun 25, 2020 via email

@zwl1619
Copy link
Author

zwl1619 commented Jun 25, 2020

@cannikin Could this feature be given the highest priority?

@thedavidprice
Copy link
Contributor

@zwl1619 maybe Auth0 or Firebase Auth is better for your needs? Auth0 offers 7,000 accounts free. For Firebase, there's more setup, but from what I understand there's no cost for web Auth: https://firebase.google.com/pricing

If you're interested in rolling your own authentication using the current Redwood Auth, here's a forum thread that covers a lot of what you'd need to do: https://community.redwoodjs.com/t/custom-github-jwt-auth-with-redwood-auth-advice-needed/610

Note: there have been a few updates and changes to the Redwood Auth package since this discussion, so do refer to the docs

Hope that helps!

@zwl1619
Copy link
Author

zwl1619 commented Jun 25, 2020

I have read the docs of Redwood Auth and the forum thread above.
Auth0 or Firebase or other third parties is inconvenient or can't be accessed in my country, so I need an independent auth system, which doesn't rely on third parties. And there are many people in my country, it is easy over 7000 accounts.

@thedavidprice
Copy link
Contributor

Auth0 or Firebase or other third parties is inconvenient or can't be accessed in my country

^^ this is really helpful for us to know @zwl1619

Did you take a look at the thread for configuring your own auth? If so, does it seem possible for you?

@FiveBoroughs
Copy link

FiveBoroughs commented Jun 26, 2020

Another option that I have been considering myself, is adding a 3rd party auth provider like netlify, auth0 and firebase but open source and self-hosted.

A few examples :

The added workload on Redwood, is simply adding a new provider, generator and doc.
While the work of setting up the authentication server, database and maintaining it is on the developer.

@mojombo mojombo added this to v1.0 in Auth Aug 18, 2020
@dthyresson dthyresson moved this from v1.0 to Done in Auth Aug 20, 2020
@dthyresson dthyresson moved this from Done to Not Doing in Auth Aug 20, 2020
@mojombo mojombo moved this from Not Doing to v1.0 in Auth Aug 25, 2020
@dthyresson
Copy link
Contributor

There is a good change that once Supabase auth support is in, by setting Prisma to use their Postgres and then using their AuthClient (which is username/password and based on GoTrue) this can give people username/password database auth.

See: #1057 and #1033

Will need a decent UI for the login and sign up forms to be more of an out-of-box solution, but people can still implement their own forms as needed.

@dthyresson dthyresson moved this from v1.0 to In progress in Auth Sep 3, 2020
Auth automation moved this from In progress to Done Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Auth
  
Done
6 participants