Skip to content

Commit 97d8122

Browse files
authored
Merge pull request formio#780 from formio/feature/global-namespace
Add Global namespace option
2 parents 037f8ce + 0f7862c commit 97d8122

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Formio.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ export default class Formio {
721721

722722
// Allow plugins to alter the options.
723723
options = Formio.pluginAlter('requestOptions', options, url);
724-
if (options.namespace) {
725-
opts.namespace = options.namespace;
724+
if (options.namespace || Formio.namespace) {
725+
opts.namespace = options.namespace || Formio.namespace;
726726
}
727727

728728
const requestToken = options.headers.get('x-jwt-token');
@@ -879,7 +879,7 @@ export default class Formio {
879879

880880
static setToken(token = '', opts) {
881881
opts = (typeof opts === 'string') ? { namespace: opts } : opts || {};
882-
var tokenName = `${opts.namespace || 'formio'}Token`;
882+
var tokenName = `${opts.namespace || Formio.namespace || 'formio'}Token`;
883883
if (!Formio.tokens) {
884884
Formio.tokens = {};
885885
}
@@ -911,7 +911,7 @@ export default class Formio {
911911

912912
static getToken(options) {
913913
options = (typeof options === 'string') ? { namespace: options } : options || {};
914-
var tokenName = `${options.namespace || 'formio'}Token`;
914+
var tokenName = `${options.namespace || Formio.namespace || 'formio'}Token`;
915915
if (!Formio.tokens) {
916916
Formio.tokens = {};
917917
}
@@ -930,7 +930,7 @@ export default class Formio {
930930
}
931931

932932
static setUser(user, opts = {}) {
933-
var userName = `${opts.namespace || 'formio'}User`;
933+
var userName = `${opts.namespace || Formio.namespace || 'formio'}User`;
934934
if (!user) {
935935
Formio.setToken(null, opts);
936936
// iOS in private browse mode will throw an error but we can't detect ahead of time that we are in private mode.
@@ -952,7 +952,7 @@ export default class Formio {
952952

953953
static getUser(options) {
954954
options = options || {};
955-
var userName = `${options.namespace || 'formio'}User`;
955+
var userName = `${options.namespace || Formio.namespace || 'formio'}User`;
956956
try {
957957
return JSON.parse(localStorage.getItem(userName) || null);
958958
}

0 commit comments

Comments
 (0)