-
Notifications
You must be signed in to change notification settings - Fork 973
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
Don't create an AuthProvider if one exists #1251
Don't create an AuthProvider if one exists #1251
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amorriscode Thanks for getting this one going! We do indeed want to check for existing and default to not overwriting. However, we also need to provide an option to override with the --force
flag.
Take a look at how the setup tailwind
command works here --> https://github.com/redwoodjs/redwood/blob/main/packages/cli/src/commands/setup/tailwind/tailwind.js
For each step in the process where a file is created or modified, there's a check if it exists. If so, it declines to run the step unless force
is passed. Example here:
redwood/packages/cli/src/commands/setup/tailwind/tailwind.js
Lines 85 to 96 in 66e39e6
const configExists = fs.existsSync( | |
path.join(getPaths().web.base, 'tailwind.config.js') | |
) | |
if (!configExists || force) { | |
await execa('yarn', ['tailwindcss', 'init']) | |
/** | |
* Later, when we can tell the vscode extension where to look for the config, | |
* we can put it in web/config/ | |
*/ | |
await execa('mv', ['tailwind.config.js', 'web/']) | |
} |
Note: you don't really need to run this check for installation of packages because Yarn will handle that by default.
Does all this make sense?
@amorriscode one more FYI. A next step here after this is merged could be to move the Take a look at how I deprecated the previous If you do this, make sure we:
Having written this out, it might be a heavier lift than I initially thought. But just let me know either way. NO pressure! |
@thedavidprice would love some feedback on the handling of redwood/packages/cli/src/commands/generate/auth/auth.js Lines 153 to 162 in 66e39e6
To handle As far as the other task goes (moving |
eb0cbd8
to
64fd4c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anthony! This is looking great and I can tell you're thinking through all the changes and edge cases really well. Lot of work here.
In addition to the change request inline, there's one more thing that's not working correctly on --force
The section starting L225 title: 'Adding auth config to GraphQL API...',
doesn't have any conditional logic in case of --force
. So what happens is that you end up with a double import:
// api/src/functions/graphql.js
...
import schemas from 'src/graphql/**/*.{js,ts}'
import services from 'src/services/**/*.{js,ts}'
import { getCurrentUser } from 'src/lib/auth'
import { getCurrentUser } from 'src/lib/auth.js'
import { db } from 'src/lib/db'
...
So in case of force
, you might just skip this step. A better way (more aligned with the work you've been doing here) would be to check if import { getCurrentUser } from 'src/lib/auth'
exists and act accordingly.
Lastly, I did make several code change requests based on Prettier warnings. Mostly curious as to why my VS Code settings were flagging these and why they didn't just update on save on your end. Maybe it's me?
fedc58a
to
3a471eb
Compare
@thedavidprice can't believe I missed the GraphQL import! 😅 As far as formatting goes, I had a TypeScript plugin that was conflicting with Prettier. Fixed my eslint plugin too so now I'll see proper warnings prior to pushing. Sorry about that! |
All good! I'll spend some time with this on Monday in hopes of getting it merged -- but it looks great first glance. Thank you so much. |
const [_, hasAuthImport] = content.match( | ||
/(import {.*} from 'src\/lib\/auth.*')/s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is throwing an error:
object null is not iterable (cannot read property Symbol(Symbol.iterator))
But I manually checked logic for case true | false and it's working well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for .match()
"Matches a string or an object that supports being matched against, and returns an array containing the results of that search, or null if no matches are found."
So I believe what's happening in the case where project does not already have auth, it returns null
and throws.
Ok, so close — just two things I found. First is the code comment about an error. Secondly, I didn't notice this before but check out these two templates files:
...and compare them to... It turns out the first two files are missing the three comment lines, which are needed for the So want to confirm you're seeing the same behavior I'm seeing here. And, if so, it seems the easy resolution is to:
Sound good? |
@thedavidprice I'm having trouble reproducing the issue. 😢 Here is a screenshot after running Here is a screenshot after running Two things to note:
Sorry I haven't been able to resolve this on my own. |
4f1d797
to
7a7f7e6
Compare
^^ Ah, that's low priority.
^^ huh, that's also weird + frustrating. I've been reverting commits in my test project after each test, so maybe that's what's keeping me from having to stop,
^^ Apology not needed. I'm here to help. And you're the one doing the work! Don't stop now. |
Ok, see my new comment inline regarding the error at line 146. Once you get setup, I think you'll hammer through this to the finish line 🏁 Here's my setup and recommendations:
|
Thanks for the help @thedavidprice. I still think the issue with running the command twice is that the first Test 1 (Fails)
Test 2 (Succeeds)
|
…ood into handle-invalid-auth-gen
Gah, now my brain hurts! I could have sworn I check this the first go around and, therefore, assumed it was something with the regex matching (admittedly I didn't dig in to that part of the code). Makes sense that Thank you and well done! 🚀 |
This PR:
Result of command:
❯ yarn rw g auth netlify yarn run v1.22.4 $ /Users/amorriscode/dev/example-blog/node_modules/.bin/rw g auth netlify Existing auth provider found ✨ Done in 1.90s.