Login check in modx from other domain

Lets say that I want example2.com to make sure that i’m logged in to example1, and if im not logged into example1.com it will redirect me to example1. Ive been stuck on this for about 2 weeks

Are you trying to get that implemented for front-end users or in the manager?

What you’re looking for is called single sign on, or SSO. Typically people use SSO to sign people into different systems from the same login but if both systems are MODX you could also do that.

The basic way to log someone in programmatically (so without them filling in their username/password on site 2) is by getting the user and calling addSessionContext, e.g.: https://gist.github.com/leviwheatcroft/70d72c2f2b3ae4e0ea4b

What you need to do though is talk with site 1 to see if the user is already logged in and if so securely transmit the necessary information back and forth. That’s something OAuth flows are often used for.

Lets say that example1.com is modx but example2.com isn’t, would this still work?

So you want to use MODX (example1) as the source of authentication?

In that case the code I linked to is not useful, as that’s for when example2 was your source of authentication.

There’s an oauth extra that you could use on your MODX site to handle the signing in through an oauth flow. It then depends on what example2 runs on and what that supports on if that will work.