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

Don't reference window in default options if it doesn't exist #73

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
storageType: 'localStorage',
storageNamespace: 'vue-authenticate',
cookieStorage: {
domain: window.location.hostname,
domain: typeof(window) === 'undefined' ? '' : window.location.hostname,
Copy link
Owner

Choose a reason for hiding this comment

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

Please use isUndefined or isDefined helper inside utils.js and extract this into a helper function like getCookieDomainUrl().

path: '/',
secure: false
},
Expand Down Expand Up @@ -55,7 +55,7 @@ export default {
name: 'facebook',
url: '/auth/facebook',
authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',
redirectUri: window.location.origin + '/',
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
Copy link
Owner

Choose a reason for hiding this comment

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

A lot of repeated work here. Again, use isUndefined or isDefined helper and extract this into a helper function like getRedirectUri(uri) where you check if window is defined. If false, return uri or null. If true, return window.location.origin + append uri.

requiredUrlParams: ['display', 'scope'],
scope: ['email'],
scopeDelimiter: ',',
Expand All @@ -68,7 +68,7 @@ export default {
name: 'google',
url: '/auth/google',
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
requiredUrlParams: ['scope'],
optionalUrlParams: ['display'],
scope: ['profile', 'email'],
Expand All @@ -83,7 +83,7 @@ export default {
name: 'github',
url: '/auth/github',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
optionalUrlParams: ['scope'],
scope: ['user:email'],
scopeDelimiter: ' ',
Expand All @@ -95,7 +95,7 @@ export default {
name: 'instagram',
url: '/auth/instagram',
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
requiredUrlParams: ['scope'],
scope: ['basic'],
scopeDelimiter: '+',
Expand All @@ -107,7 +107,7 @@ export default {
name: 'twitter',
url: '/auth/twitter',
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
oauthType: '1.0',
popupOptions: { width: 495, height: 645 }
},
Expand All @@ -116,7 +116,7 @@ export default {
name: 'bitbucket',
url: '/auth/bitbucket',
authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',
redirectUri: window.location.origin + '/',
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
optionalUrlParams: ['scope'],
scope: ['email'],
scopeDelimiter: ' ',
Expand All @@ -128,7 +128,7 @@ export default {
name: 'linkedin',
url: '/auth/linkedin',
authorizationEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
requiredUrlParams: ['state'],
scope: ['r_emailaddress'],
scopeDelimiter: ' ',
Expand All @@ -141,7 +141,7 @@ export default {
name: 'live',
url: '/auth/live',
authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
requiredUrlParams: ['display', 'scope'],
scope: ['wl.emails'],
scopeDelimiter: ' ',
Expand All @@ -154,7 +154,7 @@ export default {
name: null,
url: '/auth/oauth1',
authorizationEndpoint: null,
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
oauthType: '1.0',
popupOptions: null
},
Expand All @@ -163,7 +163,7 @@ export default {
name: null,
url: '/auth/oauth2',
clientId: null,
redirectUri: window.location.origin,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
authorizationEndpoint: null,
defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],
requiredUrlParams: null,
Expand Down