2015-07-15 12:30:11 +08:00
|
|
|
import Session from 'flarum/Session';
|
2015-07-07 13:59:21 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
/**
|
2015-07-22 08:24:49 +08:00
|
|
|
* The `preload` initializer creates the application session and preloads it
|
|
|
|
* with data that has been set on the application's `preload` property. It also
|
|
|
|
* preloads any data on the application's `preload` property into the store.
|
|
|
|
* Finally, it sets the application's `forum` instance to the one that was
|
|
|
|
* preloaded.
|
2015-07-15 12:30:11 +08:00
|
|
|
*
|
|
|
|
* `app.preload.session` should be the same as the response from the /api/token
|
|
|
|
* endpoint: it should contain `token` and `userId` keys.
|
|
|
|
*
|
|
|
|
* @param {App} app
|
|
|
|
*/
|
2015-07-22 08:24:49 +08:00
|
|
|
export default function preload(app) {
|
|
|
|
app.store.pushPayload({data: app.preload.data});
|
|
|
|
|
|
|
|
app.forum = app.store.getById('forums', 1);
|
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
app.session = new Session(
|
2015-11-05 13:47:00 +08:00
|
|
|
app.store.getById('users', app.preload.session.userId),
|
|
|
|
app.preload.session.csrfToken
|
2015-07-15 12:30:11 +08:00
|
|
|
);
|
2015-07-07 13:59:21 +08:00
|
|
|
}
|