Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

7
What do you use as primary key using nextAuth?
Post Body

Hi, I am learning doing CRUD with authentication and authorization. I will be descriptive because my phase of experience and to check if I understand it correctly.

I will share my specific use-case as example; I have nextAuth set up with a social provider (azure b2c) and I have prisma with postgres as database. Added to this, I plan to use a PHP/C# API in future.

Now let's say there is account A and account B and a posts table in the database. Account A should be able to get all posts but only be able to delete/edit posts from itself, account A.

To do that, please correct if I am wrong, you use an access token to access the API route. After that, you extract the sub claim from the access token and use that to identify the account, so only account A can access account A's posts for edit/delete.

If this is correct so far, my question is, do you use the sub claim as accountId field in posts and as primary key in a accounts table?

Or do you use a database generated cuid() as primary key in the accounts table and have a field with sub (or another name, like idp_id, google_id e.g.)? Whereafter you use the sub to query the accounts table to find the id (generated by cuid()) and use that for accountId field in posts?

tl:dr;

if (account.id (cuid()) === posts.accounId)

or

if( account.id (sub claim) === posts.accountId)

Author
User Disabled
Account Strength
0%
Disabled 1 year ago
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
237
Link Karma
37
Comment Karma
200
Profile updated: 3 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago