These are chat archives for quorrajs/quorrajs

30th
Jun 2016
maq
@maqboolkhan
Jun 30 2016 15:22
hello @harishanchu
after adding export.modules my service provider is running awesomely alhamdulilah
:0
:)
Harish
@harishanchu
Jun 30 2016 15:27
:smile:
maq
@maqboolkhan
Jun 30 2016 20:13
@harishanchu can i have access to req object using App object??
Harish
@harishanchu
Jun 30 2016 20:16
App object is a singleton. Req object is generated per http request.
maq
@maqboolkhan
Jun 30 2016 20:17
oops
Harish
@harishanchu
Jun 30 2016 20:17
You can access request object inside middlewares, filters and routes.
maq
@maqboolkhan
Jun 30 2016 20:17
meanns i cant access req.auth in service provider?
Harish
@harishanchu
Jun 30 2016 20:18
Nope
maq
@maqboolkhan
Jun 30 2016 20:18
ohh
Harish
@harishanchu
Jun 30 2016 20:18
Service providers are meant for adding services to the framework
But a middleware can have req access
maq
@maqboolkhan
Jun 30 2016 20:19
actually m a big fan of how laravel add

Harish
@harishanchu
Jun 30 2016 20:19
You can register a custom middleware from ur service provider too
maq
@maqboolkhan
Jun 30 2016 20:20
{% block content %}
    {% if auth_guest() %}
        please login to continue
    {% else %}
        welcome {{  auth_user().name }}
    {% endif %}
{% endblock %}
so since the day i know Quorra i am struggling to make this functionality available in Quorra :smile:
ohhhh
Harish
@harishanchu
Jun 30 2016 20:21
You can do the same in quorra too
maq
@maqboolkhan
Jun 30 2016 20:21
how ? by sending with res?
Harish
@harishanchu
Jun 30 2016 20:22
Nope
maq
@maqboolkhan
Jun 30 2016 20:22
then?
Harish
@harishanchu
Jun 30 2016 20:22
Req object have auth service added by the auth middlewares
Which includes methods to check whether a user is authenticated or whether guest etc
maq
@maqboolkhan
Jun 30 2016 20:23
but laravel do in our views?
Harish
@harishanchu
Jun 30 2016 20:25
You just need to write custom middleware which should add map those methods from req.auth service to req.locals object
Then ur templates will have access to it
maq
@maqboolkhan
Jun 30 2016 20:25
res.locals or req.locals?
yes i am exactly doing this
:)
Harish
@harishanchu
Jun 30 2016 20:25
Sorry req.locals
maq
@maqboolkhan
Jun 30 2016 20:26
now one more question if i write middleware then how i will able to distribute as a quorra package?
Harish
@harishanchu
Jun 30 2016 20:27
One another simple way is just map it from the global before filter in the global js file
For now you have to develop it as a service provider package
maq
@maqboolkhan
Jun 30 2016 20:28
now point is back
i cant access req object in SP :'(
Harish
@harishanchu
Jun 30 2016 20:28
And ur service provider should register ur custom middleware
Ie service provider package should include ur custom middleware as well
maq
@maqboolkhan
Jun 30 2016 20:29
getting harder
Harish
@harishanchu
Jun 30 2016 20:30
Nope
Did you understand how to expose methods to res.locals from a custom middleware?
maq
@maqboolkhan
Jun 30 2016 20:31
yes
its very easy
but i cant understand how to register middleware from SP
i think i should read docs
Harish
@harishanchu
Jun 30 2016 20:33
Now just write a service provider and in its boot method register ur middleware with this.__app.middleware(require(<middleware class>))
That's it
Now with every request ur custom middleware will run along with default middlewares
Understood?
Harish
@harishanchu
Jun 30 2016 20:46
One more thing. As I said before quorra don't have fixed package structure now.. you can make any npm package work with quorra
You can also publish a package just with middleware
To make use of that middleware in quorra u need to require it in the global.js file and register with the app as a custom middleware with app.middleware method