<commit_before>define(['vue', 'keycloak'], function (Vue, Keycloak) {
    "use strict";

    var keycloakAuth = null;
    var enforceLogin = false;

    var logout = function () {
        keycloakAuth.logout().success(function () {
            data.loggedIn = false;
            data.token = null;
        }).error(function () {
            console.log("WTF");
        });
    };

    var login = function () {
        keycloakAuth.login()
            .success(function () { data.loggedIn = true; })
            .error  (function () { data.loggedIn = false; });
    };

    var data = new Vue({
        el: "#login-area",
        data: {
            loginAvailable: true,
            loggedIn: false,
            login: login,
            logout: logout,
            token: null
        }
    });

    function registerCallbacks() {
		keycloakAuth.onAuthSuccess = function () {
			console.log("Auth Success!!");
		};
	
		keycloakAuth.onAuthRefreshSuccess = function () {
			console.log("Auth Refreshed!!");
		};
	
		keycloakAuth.onAuthLogout = function () {
			console.log("Logged out!!");
		};
    }
    
    function initKeyCloak(vueApp, callback) {
        // issue I had: when KC init encounters an error 400, neither success nor error get called
        keycloakAuth.init({
            onLoad: enforceLogin ? "login-required" : "check-sso"
        }).success(function (authenticated) {
            vueApp.loggedIn = authenticated;
            console.log('Authenticated: ' + authenticated);
            if (authenticated) {
                data.token = keycloakAuth.token;
                console.log('local time: ' + new Date().getTime() / 1000);
                console.log('iat: ' + keycloakAuth.tokenParsed.iat);
                console.log('diff: ' + (new Date().getTime() / 1000 - keycloakAuth.tokenParsed.iat));
                console.log('exp in: ' + (keycloakAuth.tokenParsed.exp - new Date().getTime() / 1000));
                console.log('isExpired: ' + keycloakAuth.isTokenExpired());
            }
            if (callback) {
                callback(data);
            }
        }).error(function (err) {
            vueApp.loginAvailable = false;
            data.token = null;
            console.log("Error initializing keycloak");
            console.log(err);
            if (callback) {
                callback(data);
            }
        });
    }

    function initialize(keyCloakUrl, callback) {
		keycloakAuth = new Keycloak(keyCloakUrl);
        registerCallbacks();
		initKeyCloak(data, callback);
        console.log("Auth initialized");
    }

    return {
        initialize: initialize,<commit_msg>keycloak integration - add check if token expired<commit_after>define(['vue', 'keycloak'], function (Vue, Keycloak) {
    "use strict";

    var keycloakAuth = null;
    var enforceLogin = false;

    var logout = function () {
        keycloakAuth.logout().success(function () {
            data.loggedIn = false;
            data.token = null;
        }).error(function () {
            console.log("WTF");
        });
    };

    var login = function () {
        keycloakAuth.login()
            .success(function () { data.loggedIn = true; })
            .error  (function () { data.loggedIn = false; });
    };

    var data = new Vue({
        el: "#login-area",
        data: {
            loginAvailable: true,
            loggedIn: false,
            login: login,
            logout: logout,
            token: null
        }
    });

    function registerCallbacks() {
		keycloakAuth.onAuthSuccess = function () {
			console.log("Auth Success!!");
		};
	
		keycloakAuth.onAuthRefreshSuccess = function () {
			console.log("Auth Refreshed!!");
		};
	
		keycloakAuth.onAuthLogout = function () {
			console.log("Logged out!!");
		};
    }
    
    function initKeyCloak(vueApp, callback) {
        // issue I had: when KC init encounters an error 400, neither success nor error get called
        keycloakAuth.init({
            onLoad: enforceLogin ? "login-required" : "check-sso"
        }).success(function (authenticated) {
            vueApp.loggedIn = authenticated;
            console.log('Authenticated: ' + authenticated);
            if (authenticated) {
                data.token = keycloakAuth.token;
                console.log('local time: ' + new Date().getTime() / 1000);
                console.log('iat: ' + keycloakAuth.tokenParsed.iat);
                console.log('diff: ' + (new Date().getTime() / 1000 - keycloakAuth.tokenParsed.iat));
                console.log('exp in: ' + (keycloakAuth.tokenParsed.exp - new Date().getTime() / 1000));
                console.log('isExpired: ' + keycloakAuth.isTokenExpired());
                window.setInterval(function () {
                    keycloakAuth.updateToken(15).success(function () {
                        console.info('updateToken success.')
                    }).error(function () {
                        console.error('Fehler beim Aktualisieren des Keycloak-Tokens')
                    })
                }, 10000);
            }
            if (callback) {
                callback(data);
            }
        }).error(function (err) {
            vueApp.loginAvailable = false;
            data.token = null;
            console.log("Error initializing keycloak");
            console.log(err);
            if (callback) {
                callback(data);
            }
        });
    }

    function initialize(keyCloakUrl, callback) {
		keycloakAuth = new Keycloak(keyCloakUrl);
        registerCallbacks();
		initKeyCloak(data, callback);
        console.log("Auth initialized");
    }

    return {
        initialize: initialize,
{'fraction_non_alphanumeric': 0.12925409980603067, 'fraction_numerical': 0.006524422500440839, 'mean_word_length': 1.8275174476570288, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '487562', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1579, 'n_words': 314}