-
Notifications
You must be signed in to change notification settings - Fork 251
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 reference window in default options if it doesn't exist #73
base: master
Are you sure you want to change the base?
Changes from all commits
4709e57
77976c8
ba3bf2c
3435bf9
8d398d4
3794148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { | ||
objectExtend, | ||
formatCookie, | ||
getCookieDomain, | ||
parseCookies | ||
} from '../utils.js'; | ||
|
||
class CookieStorage { | ||
constructor(defaultOptions) { | ||
this._defaultOptions = objectExtend({ | ||
domain: window.location.hostname, | ||
domain: getCookieDomain(), | ||
expires: null, | ||
path: '/', | ||
secure: false | ||
secure: false, | ||
getCookieFn: this._getCookie, | ||
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. I didn't have time to think about this logic these past few days, but my first impression is that I don't like it too much. The main reason is that the ability to authenticate a user on the server side is by using cookies. I will have to think a bit more about this. For now, I suggest that you make it compilable in SSR, and later we can try to think about a solution to persist authentication state over SSR. |
||
}, defaultOptions); | ||
} | ||
|
||
|
@@ -21,7 +23,8 @@ class CookieStorage { | |
} | ||
|
||
getItem(key) { | ||
const cookies = parseCookies(this._getCookie()); | ||
const options = objectExtend({}, this._defaultOptions); | ||
const cookies = parseCookies(options.getCookieFn()); | ||
return cookies.hasOwnProperty(key) ? cookies[key] : null; | ||
} | ||
|
||
|
@@ -46,4 +49,4 @@ class CookieStorage { | |
} | ||
} | ||
|
||
export default CookieStorage | ||
export default CookieStorage |
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.
These two functions are contextually highly connected only to
options.js
file and nowhere else. There is no reason they should be located inutils.js
file. Please move them back inoptions.js
file.