react icon indicating copy to clipboard operation
react copied to clipboard

manually including the jwt token

Open banchanKiro opened this issue 5 years ago • 3 comments

I am new to formio and I have a query that I have not found any solution to.

My system consists of a sailsjs back end, a react front end, and a local instance of form io. I have connected to the authentication of both the sails and formio. But with this custom authentication, I cant seem to be able to make formio properly authenticate my user.

My question is, where does the formio token gets stored when i log in, and from where is it being read, and adding to the headers when I am trying to submit/update submission.

banchanKiro avatar Apr 17 '20 03:04 banchanKiro

The token is stored in localStorage as formioToken. When sent to servers it is at headers['x-jwt-token'].

You can modify this by creating a formio.js plugin that intercepts requests and changes the location of the token. https://github.com/formio/formio.js/wiki/Fetch-Plugin-API

randallknutson avatar Apr 17 '20 14:04 randallknutson

Thank you very much @randallknutson . This has resolved my issues.

banchanKiro avatar Apr 17 '20 23:04 banchanKiro

Hi sorry to disturb again.

When calling the getForm() action, Im getting an error because the root selector is getting problem. _selectors.selectRoot(...) is undefined. I think the reason is because my formio reducers are not in the root state, but in a sub-state called formioStore

formioStore: combineReducers({
    auth: formioAuth(),
    form: form({ name: 'form' }),
    forms: forms({ name: 'forms', query: { type: 'form', tags: 'common' } }),
    submission: submission({ name: 'submission' }),
    submissions: submissions({ name: 'submissions' }),
    event: combineReducers({
      form: form({ name: 'event' }),
      submission: submission({ name: 'event' }),
      submissions: submissions({ name: 'event' }),
    }),
  }),

So My question is, Is this the reason for the error and if so is there a way to change the default root in some configuration in formio?

This is the error in chrome:

TypeError: Cannot read property 'form' of undefined
selectForm
C:/Users/babac/Indus Action/cms-front-end/node_modules/react-formio/lib/modules/form/selectors.js:11
   8 | var _selectors = require('../root/selectors');
   9 | 
  10 | var selectForm = exports.selectForm = function selectForm(name, state) {
> 11 |   return (0, _selectors.selectRoot)(name, state).form;
  12 | };

banchanKiro avatar Apr 18 '20 21:04 banchanKiro

I am closing the issue as it was created too long ago and there are no new comments here. I hope it was resolved. If not, please reopen it. Thanks!

TanyaGashtold avatar Aug 31 '23 13:08 TanyaGashtold