req.context.if_logged_in()
To aid in the process of routing users to the correct location, Joystick includes a helper function req.context.if_logged_in()
to trigger custom behavior if a user is already logged in.
/index.server.js
import joystick from '@joystick.js/node';
joystick.app({
routes: {
'/': async (req = {}, res = {}) => {
req.context.if_logged_in('/dashboard', () => {
res.render('ui/pages/index/index.js');
};)
},
'/login': async (req = {}, res = {}) => {
req.context.if_logged_in('/dashboard', () => {
res.render('ui/pages/login/index.js');
};)
},
},
});
Above, we call to req.context.if_logged_in()
, first passing the route that the user should be redirected to if they are logged in, and second, a callback function describing what to do if they are not logged in.
API Reference
req.context.if_logged_in()
Function API
Function API
req.context.if_logged_in(redirect_path: string, callback: function) => void;
Arguments
-
redirect_path string
If there is a current user, redirect them to this path.
-
callback function
If there is not a current user, call this function.