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

Bradley/dev mode credentials #286

Closed

Conversation

bradleyDean
Copy link
Contributor

@bradleyDean bradleyDean commented May 5, 2023

What?
Create serve-dev command which automatically authenticates the user and gives them certain permissions, as described in this issue.

How?
The issue linked above described the process pretty well, but notice that createContext now creates a closure so that seperate requests will not keep creating new user id's. I also created a launch config object so we can run the new serve-dev command using a debugger.

Validation?
I used the serve-dev command to add areas to the db in the graphql playground. I was shaky on how to get the necessary uuid's (for specifying which specific area I wanted to delte, fetch, etc), so it would probably be a good idea for someone more familiar with the API to run the new command, then exercise other API endpoints, just so we can validate it with more code paths. Alternatively, maybe someone more familiar with using the API and I can chat on discord and I'll run additional validation myself.

Tests?
I haven't implemented any tests yet :(
If anyone thinks I should, let me know and I'll get on it.

@vnugent vnugent requested a review from zichongkao May 6, 2023 12:27
@bradleyDean bradleyDean marked this pull request as draft May 6, 2023 20:41
@bradleyDean
Copy link
Contributor Author

bradleyDean commented May 6, 2023

I converted to a draft because I decided to go ahead and write some tests for this.
I do not plan on changing the logic in the diffs (unless the tests reveal bugs!), so it shouldn't be a waste of time to have a look at the diffs in the mean time!

Update:
I ran into issues writing tests, having to do with a tricky race condition with the setting of the env.GOD_MODE variable. I am moving forward without resolving this for now, but if anyone is concerned about it, let me know and I'll put more time into figuring it out.

I did manually test that I can use serve-dev to autenticate mutations involving areas and orgs.

uuid: undefined
if (process.env.NODE_ENV === 'development') {
testUUID = muid.v4()
console.log(`The user.uuid for this session is: ${testUUID.toString()}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use logger.info() instead?

src/auth/middleware.ts Outdated Show resolved Hide resolved
}

if (process.env.NODE_ENV === 'development' && (user.uuid == null)) {
user.roles = ['admin', 'editor']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the three roles that currently exist are editor, user_admin and org_admin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I changed it to include all three roles.

@bradleyDean bradleyDean marked this pull request as ready for review May 9, 2023 16:41
@bradleyDean bradleyDean marked this pull request as draft May 9, 2023 16:42
@bradleyDean bradleyDean marked this pull request as ready for review May 9, 2023 22:10
@vnugent
Copy link
Contributor

vnugent commented Jul 4, 2023

@bradleyDean can you please rebase to fix conflicts?

@l4u532
Copy link
Contributor

l4u532 commented Jan 2, 2024

Should be closed since this got implemented by #371

@vnugent vnugent closed this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants