We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
this.app
This is my code
import Marty from 'marty'; import LoginStore from '../stores/loginStore'; import config from '../config.json'; function createAuthHeader(token) { let scheme = config.API.AUTH_SCHEME; return `${scheme} token=${token}`; }; Marty.HttpStateSource.addHook({ id: 'addToken', before(req) { let token = this.app.loginStore.getToken(); //error here //Uncaught TypeError: Cannot read property 'loginStore' of undefined if (token) { req.headers['Authorization'] = createAuthHeader(token); } } });
How can I use this.app from within a hook? Thank you.
The text was updated successfully, but these errors were encountered:
That's really weird. Are you sure you're properly passing up options to the super constructor of HttpStateSource?
options
super
HttpStateSource
Sorry, something went wrong.
I have no constructor on HttpStateSource thats the code:
import Marty from 'marty'; import {format} from 'util'; import config from '../config.json'; var base = config.API.ROOT; var endpoint = base + 'users'; function handleRes(res) { let json = res.json(); if (res.ok) return json; throw new Error("Error in response", json, res); } class UserHttpAPI extends Marty.HttpStateSource { login(email, password) { var url = format(endpoint + '/login'); return this.post({ url: url, body: { email: email, password: password } }).then(handleRes); } getSelf() { return this.get(endpoint + '/self').then(handleRes) } } export default UserHttpAPI;
That's really weird. Can you log what this resolves as in your hook?
this
No branches or pull requests
This is my code
How can I use
this.app
from within a hook?Thank you.
The text was updated successfully, but these errors were encountered: