[Tutorial/TypeScript] TS warning when no RBAC scheme is implemented
See original GitHub issueReporting this non-critical finding here as advised:
Discovered in https://redwoodjs.com/docs/tutorial/chapter4/authentication#an-admin-section
The auth.ts
file generated by yarn rw setup auth dbAuth
expects a roles property to exist on the user object. However, implementers may choose (like in this tutorial chapter) not to implement role-based access control.
In that case, we’re getting
Property 'roles' does not exist on type '{ id: number; email: string; }'.ts(2339)
in three places in api/src/lib/auth.ts
.
Maybe there is way to expand the interface InferredCurrentUser
, making this an optional field?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Node.js and TypeScript Tutorial: Secure an Express API - Auth0
Learn how to use TypeScript and Auth0 to secure a feature-complete Express.js API. Tutorial on how to use Auth0 to implement authorization in...
Read more >How to get rid of the warning .ts file is part of the TypeScript ...
Explicitly adding the 'files' array with the 2 entry files above, cleared the warnings.
Read more >The starting point for learning TypeScript
TypeScript Documentation. Get Started. Quick introductions based on your background or preference. TS for the New Programmer · TypeScript for JS ...
Read more >Role-Based Access Control (RBAC) | RedwoodJS Docs
But that will fail with an error: • Step 0 Added the required column `role` to the `User` table without a default value....
Read more >Widgets Development Guide | ThingsBoard Community Edition
There is no subscription data and no special widget API was used. Only custom showAlert function was implemented showing an alert with the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can’t decide if I agree or not here 😆
I love the help TS gives you in spotting errors like what you describe above. But I also don’t like it when generated code is throwing errors in my face 🙂 Always leaves me with questions like “Have I done something wrong?”, “Is the generator broken?”, “What do I need to do to fix this?” etc.
I need to go through the tutorial with a TS project to see this for myself to be able to give any good suggestions on how to handle this
I had totally forgotten about the fact i had written this issue when i handed in #5856 today 😆 Guess i lost track of it, sorry for not following up earlier.
@Tobbe
That’s exactly where i’m coming from. The question “Is the RedwoodJS generator somehow broken?” should never come up in the DX, i guess that’s what everybody is working for here. Imho it must not ever generate code that violates its own ESLint rules (see #5827) or worse (like in this case) generates invalid types that will make
yarn rw check-types
fail in order to build trust.@dac09
What about adding some JSDoc here, linking to the
getCurrentUser
function and giving the heads-up that roles will always be undefined unless included in the selection … would that suffice?