prisma / prisma-examples

šŸš€ Ready-to-run Prisma example projects
https://www.prisma.io/docs/
Apache License 2.0
5.99k stars 1.41k forks source link

Idea for an example (JWT Auth Server) #2838

Open gautvm opened 3 years ago

gautvm commented 3 years ago

I figured creating an example of making a JWT auth server using Prisma might be useful, with access tokens, user storing, sessions, password hashing, isAuth middleware, etc.

The routes would look like this

POST

DELETE

PUT

I have a GitHub repo with some of it implemented, though I am going to implement sessions as well.

If this idea gets approved, I will write the example in a way that follows the style of the other examples. I could update this proposed idea in any way that the Prisma team will like it to be.

The data model would look like this

model User {
  id Int @id @default(autoincrement())
  username String @unique
  email String @unique
  password String
  sessionKey String
}
ruheni commented 3 years ago

This is a great idea!

We can go ahead with this.

Before you do, I have a few recommendations. We like to maintain consistency and make them as simple as possible for beginners and experienced developers.

A general rule of thumb is to test the example to ensure they are working as expected locally before a review. We're working on automating the testing for the *-auth examples.

Once you're done creating the example, add the test in the relevant test .github/test folder. You add a README in the .github./readmes folder and follow our Contributing Guide on generating a README.

Lastly, include the example and the link in the repo's main README file under the relevant section.

If you hit a snag, don't hesitate to let us know. šŸ™‚

gautvm commented 3 years ago

Thanks! Will do.

IBRAHIMDANS commented 1 year ago

Good idea, but I think it's more optimized to have a new model PasswordModel to allow the user to have several login methods. Also i check if new password are used by user for example: Users (id, email, passwordId, passwords []) ===> Password(id, userId, isActive, createdAt, updatedAt)

gautvm commented 1 year ago

Good idea, but I think it's more optimized to have a new model PasswordModel to allow the user to have several login methods. Also i check if new password are used by user for example: Users (id, email, passwordId, passwords []) ===> Password(id, userId, isActive, createdAt, updatedAt)

I think it might be better to have an enum like OAuthConnectionType rather than a Password model. Feel free to implement this in the PR, if you'd like (I'll be finishing it up soon).

XprabhatX commented 3 months ago

@gautvm is it implemented yet? Because I saw some tests in pr #2869 are failing (But it's an old pr and this issue is open).