Skip to content

Commit 45a9f6d

Browse files
committed
Refactor cookie domain url
1 parent 4709e57 commit 45a9f6d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/options.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { isUndefined } from './utils.js';
2+
3+
function getCookieDomainUrl(path = '') {
4+
return isUndefined(window) ? path : `${window.location.hostname}${path}`;
5+
}
16
/**
27
* Default configuration
38
*/
@@ -13,7 +18,7 @@ export default {
1318
storageType: 'localStorage',
1419
storageNamespace: 'vue-authenticate',
1520
cookieStorage: {
16-
domain: typeof(window) === 'undefined' ? '' : window.location.hostname,
21+
domain: getCookieDomainUrl(),
1722
path: '/',
1823
secure: false
1924
},
@@ -55,7 +60,7 @@ export default {
5560
name: 'facebook',
5661
url: '/auth/facebook',
5762
authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',
58-
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
63+
redirectUri: getCookieDomainUrl('/'),
5964
requiredUrlParams: ['display', 'scope'],
6065
scope: ['email'],
6166
scopeDelimiter: ',',
@@ -68,7 +73,7 @@ export default {
6873
name: 'google',
6974
url: '/auth/google',
7075
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
71-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
76+
redirectUri: getCookieDomainUrl(),
7277
requiredUrlParams: ['scope'],
7378
optionalUrlParams: ['display'],
7479
scope: ['profile', 'email'],
@@ -83,7 +88,7 @@ export default {
8388
name: 'github',
8489
url: '/auth/github',
8590
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
86-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
91+
redirectUri: getCookieDomainUrl(),
8792
optionalUrlParams: ['scope'],
8893
scope: ['user:email'],
8994
scopeDelimiter: ' ',
@@ -95,7 +100,7 @@ export default {
95100
name: 'instagram',
96101
url: '/auth/instagram',
97102
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
98-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
103+
redirectUri: getCookieDomainUrl(),
99104
requiredUrlParams: ['scope'],
100105
scope: ['basic'],
101106
scopeDelimiter: '+',
@@ -107,7 +112,7 @@ export default {
107112
name: 'twitter',
108113
url: '/auth/twitter',
109114
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
110-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
115+
redirectUri: getCookieDomainUrl(),
111116
oauthType: '1.0',
112117
popupOptions: { width: 495, height: 645 }
113118
},
@@ -116,7 +121,7 @@ export default {
116121
name: 'bitbucket',
117122
url: '/auth/bitbucket',
118123
authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',
119-
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
124+
redirectUri: getCookieDomainUrl('/'),
120125
optionalUrlParams: ['scope'],
121126
scope: ['email'],
122127
scopeDelimiter: ' ',
@@ -128,7 +133,7 @@ export default {
128133
name: 'linkedin',
129134
url: '/auth/linkedin',
130135
authorizationEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
131-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
136+
redirectUri: getCookieDomainUrl(),
132137
requiredUrlParams: ['state'],
133138
scope: ['r_emailaddress'],
134139
scopeDelimiter: ' ',
@@ -141,7 +146,7 @@ export default {
141146
name: 'live',
142147
url: '/auth/live',
143148
authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',
144-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
149+
redirectUri: getCookieDomainUrl(),
145150
requiredUrlParams: ['display', 'scope'],
146151
scope: ['wl.emails'],
147152
scopeDelimiter: ' ',
@@ -154,7 +159,7 @@ export default {
154159
name: null,
155160
url: '/auth/oauth1',
156161
authorizationEndpoint: null,
157-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
162+
redirectUri: getCookieDomainUrl(),
158163
oauthType: '1.0',
159164
popupOptions: null
160165
},
@@ -163,7 +168,7 @@ export default {
163168
name: null,
164169
url: '/auth/oauth2',
165170
clientId: null,
166-
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
171+
redirectUri: getCookieDomainUrl(),
167172
authorizationEndpoint: null,
168173
defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],
169174
requiredUrlParams: null,

0 commit comments

Comments
 (0)