clarkwinkelmann
I have a main site, and now I'm building the forum for the main site with flarum.
On my main site, I have some users, and there are things like profiles, achievements, and so on.
On the forum, I want to make it so when a user that was already registered on the main site logs in, their "forum account" will be linked to their "main site" account.
So, to do that, I thought about listening for the "UserLoggedIn" event, and then calling a Javascript function that would check if the user that just logged in matches a user registered on the main site, and if so, send some data to the main site's database, and do some other operations, like counting their forum posts, and so on.
So far I was able to add javascript to the page by adding the js file directly to the forum's header under /admin#/appearance, but I'm not sure how to call the functions with the login details when the user logs in.
I know how to call a function, but I don't know how to pass parameters to it.
For now I'm doing like this:
$events->listen(UserLoggedIn::class, function (UserLoggedIn $event) {
// User logged in
// TODO: Call javascript function to check if the user is also on main site, and connect them if so.
if ($event->isForum()) {
$event->addAssets(DIR."/js/forum/dist/extension.js");
$event->addBootstrapper("metsuryu/flarum-lantea/main");
}
});
extension.js simply calls a function that was inside the .js file that was added in the header, but I have no way to pass any login parameters to it.
Any idea how I can do that?
Anyway, I'm not even sure how to get the login details, could you point me to the documentation that shows it?
Thank you.
Edit: Actually that code I posted doesn't work. I took it from here:
$events->listen(ConfigureClientView::class, function (ConfigureClientView $event) {
if ($event->isForum()) {
$event->addAssets(DIR."/js/forum/dist/extension.js");
$event->addBootstrapper("metsuryu/flarum-lantea/main");
}
});
And replaced ConfigureClientView with UserLoggedIn, but it didn't work.
So, how do I call a function when a user logs in?