-
Notifications
You must be signed in to change notification settings - Fork 393
chore: inject the Authlify Token in netlify dev
#4167
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
Conversation
📊 Benchmark resultsComparing with fc1c991 Package size: 362 MB⬆️ 0.14% increase vs. fc1c991
Legend
|
authlifyJWT == null | ||
? {} | ||
: { | ||
ONEGRAPH_AUTHLIFY_TOKEN: { |
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.
follows the format expected by injectEnvVariables
. Not sure if there's a helper to create this?
src/lib/functions/server.js
Outdated
@@ -105,6 +106,11 @@ const createHandler = function ({ functionsRegistry }) { | |||
rawQuery, | |||
} | |||
|
|||
if (config.authlify && config.authlify.authlifyTokenId != null) { |
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.
follows https://github.com/netlify/proxy/pull/719 by injecting the token whenever there's an authlify token ID, and not only when --graph
is passed.
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.
The only concern I have is that we're exposing authlifyToken
to end users when it should probably be netlifyGraphToken
. Let's say that's fine for the beta period, and then migrate users off of it (well) before GA.
Tests seem flakey and unrelated to my changes -- they fail in different OSes in different runs, for different tests 😢. I'm planning on merging this later today if there are no objections. I'll follow up with a fix if indeed there are broken things. EDIT: trying to get them to pass after #4164 |
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.
Hi @sgrove and @anmonteiro.
I added 2 comments
src/commands/dev/dev.js
Outdated
@@ -253,7 +254,29 @@ const dev = async (options, command) => { | |||
) | |||
} | |||
|
|||
await injectEnvVariables({ env: command.netlify.cachedConfig.env, site }) | |||
const startNetlifyGraphWatcher = Boolean(options.graph) | |||
const netlifyToken = await command.authenticate() |
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 will open up a browser and authenticate if users are not logged in.
This is not the expected behavior for the CLI as ntl dev
should not require it.
We can put this under the graph
condition for now, but we should probably have better error reporting.
Users can also pass --offline
to the dev
command which should prevent any requests from being sent.
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.
we'll need the netlify bearer token for the user. What's an alternative way of getting it?
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.
That's the way to get it. We should only do it when running with graph
I believe
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.
There’s also the API Authentication use case. I can do it only in the presence of an authlify token ID, then. Appreciate the review!
authlifyJWT == null | ||
? {} | ||
: { | ||
ONEGRAPH_AUTHLIFY_TOKEN: { |
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.
Where do we want ONEGRAPH_AUTHLIFY_TOKEN
injected to?
The PR description says builds and functions.
This injects it into functions and dev command, but not builds
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.
It's injected in builds via Bitballoon.
Are there local builds where I should inject the variable too?
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.
The CLI has a build command
cli/src/commands/build/build.js
Line 24 in e763556
command.setAnalyticsPayload({ dry: options.dry }) |
The CLI gets all the configuration, including environment variables from netlify/config
, so I wonder if it will be easier to implement this PR in that package.
See the code to retrieve site information in https://github.com/netlify/build/blob/dc76f4b27a9fe92395c7d20346ce1655f8340d8c/packages/config/src/api/site_info.js
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.
I feel like this is more specific to the CLI than the generic config package.
@erezrokah are you on board if we merge this with the current functionality to unblock Mathias's upcoming talk and make the build improvements later?
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.
Hi @anmonteiro, I'm good with unblocking.
I think it will great to follow up with a test case for this, do you mind opening an issue for it?
Do you mind opening another issue for supporting this in ntl build
? If we inject the auth token in our build system, will should inject it to ntl build
too.
This is released in https://github.com/netlify/cli/releases/tag/v8.15.5 |
Thanks, @erezrokah! I opened #4182 and #4181 per your suggestions. |
🎉 Thanks for submitting a pull request! 🎉
Summary
ONEGRAPH_AUTHLIFY_TOKEN
variableauthlifyToken
to the eventFor us to review and ship your PR efficiently, please perform the following steps:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)