-
Notifications
You must be signed in to change notification settings - Fork 42
Improve accessToken logic
#228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| const dfn = require('@netlify/open-api') | ||
| const get = require('lodash.get') | ||
| const set = require('lodash.set') | ||
| const pWaitFor = require('p-wait-for') | ||
|
|
||
| const deploy = require('./deploy') | ||
|
|
@@ -41,15 +39,24 @@ class NetlifyAPI { | |
| } | ||
|
|
||
| get accessToken() { | ||
| return (get(this, 'defaultHeaders.Authorization') || '').replace('Bearer ', '') || null | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const { | ||
| defaultHeaders: { Authorization }, | ||
| } = this | ||
| if (typeof Authorization !== 'string' || !Authorization.startsWith('Bearer ')) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is slightly different, but seems to capture the actual intent. @erezrokah What do you think?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this looks much better |
||
| return null | ||
| } | ||
|
|
||
| return Authorization.replace('Bearer ', '') | ||
| } | ||
|
|
||
| set accessToken(token) { | ||
| if (token) { | ||
| set(this, 'defaultHeaders.Authorization', `Bearer ${token}`) | ||
| } else { | ||
| if (!token) { | ||
| // eslint-disable-next-line fp/no-delete | ||
| delete this.defaultHeaders.Authorization | ||
| return | ||
| } | ||
|
|
||
| this.defaultHeaders.Authorization = `Bearer ${token}` | ||
| } | ||
|
|
||
| get basePath() { | ||
|
|
||
This file was deleted.
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 was previously removed by #93
However,
omit.jsdoes not usecore-jsanymore, so we can use it again.