diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index a796e88..1244768 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -504,6 +504,7 @@ class UserSerializer(serializers.ModelSerializer): transactions = serializers.SerializerMethodField() door_code = serializers.SerializerMethodField() wifi_pass = serializers.SerializerMethodField() + app_version = serializers.SerializerMethodField() class Meta: model = User @@ -517,6 +518,7 @@ class UserSerializer(serializers.ModelSerializer): 'is_staff', 'door_code', 'wifi_pass', + 'app_version', #'usages', ] depth = 1 @@ -541,6 +543,9 @@ class UserSerializer(serializers.ModelSerializer): else: return None + def get_app_version(self, obj): + return settings.APP_VERSION + class MyRegisterSerializer(RegisterSerializer): first_name = serializers.CharField(max_length=32) diff --git a/apiserver/apiserver/settings.py b/apiserver/apiserver/settings.py index 167660b..d8f2cfc 100644 --- a/apiserver/apiserver/settings.py +++ b/apiserver/apiserver/settings.py @@ -282,5 +282,7 @@ DEFAULT_FROM_EMAIL = 'Protospace Portal ' if DEBUG: logger.info('Debug mode ON') logger.info('Test logging for each thread') +APP_VERSION = 1 # TODO: automate this + #import logging_tree #logging_tree.printout() diff --git a/webclient/src/App.js b/webclient/src/App.js index 644beb2..8daf355 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -27,6 +27,8 @@ import { PasswordReset, ConfirmReset } from './PasswordReset.js'; import { NotFound, PleaseLogin } from './Misc.js'; import { Footer } from './Footer.js'; +const APP_VERSION = 1; // TODO: automate this + function App() { const [token, setToken] = useState(localStorage.getItem('token', '')); const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false'))); @@ -98,6 +100,11 @@ function App() { darkmode.showWidget(); }, []); + if (user && user?.app_version !== APP_VERSION) { + setUserCache(false); + window.location.reload(); + } + return (