I don't know exactly how github does this. But one possibility is to use a visibilitychange event handler. This will trigger when you switch tabs. The event handler can check the cookies for the current site, and determine if someone logged in another tab.
https://developer.mozilla.org/en-US/docs/Web/Events/visibilitychange
Usually tabs share no state. But two tabs have the same origin (domain name), they share cookies. In django you typically render the csrf token to the html dom with the template tag {% csrf_token %}, which means that if the current tab's csrf token was invalidated (which happens when you sign in), you must refresh the page to get a fresh token.
One way to do attach such an event listener is this:
// check cookie for `logged_in` substring (this only works for insecure cookies. Not http-only)
const isLoggedIn = () => document.cookie.includes('logged_in')
// check cookie for changes when you open this tab
const signInSpy = () => {
document.visibilitystate === 'visible' &&
isLoggedIn() &&
alert('refresh, please')
}
// only attach event handler when not signed in.
document.onvisibilitychange = isLoggedIn() ? null : signInSpy
This example only works if logged_in is not a http-only cookie. For other options for communicating between tabs, see this question:
Communication between tabs or windows