From 9ed002c87902cd707836ebdca819ea91b4ec42cd Mon Sep 17 00:00:00 2001 From: "Arthur Pacaud (arthuro555)" Date: Mon, 15 Jan 2024 14:00:14 +0100 Subject: [PATCH] Add expression to read the authenticated user unique identifier (#6192) * This is useful if you want to interface with a third party or in-house solution to store user data. --- Extensions/PlayerAuthentication/JsExtension.js | 17 +++++++++++++++++ .../playerauthenticationtools.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Extensions/PlayerAuthentication/JsExtension.js b/Extensions/PlayerAuthentication/JsExtension.js index 49477e8b48..19a68d8843 100644 --- a/Extensions/PlayerAuthentication/JsExtension.js +++ b/Extensions/PlayerAuthentication/JsExtension.js @@ -169,6 +169,23 @@ module.exports = { ) .setFunctionName('gdjs.playerAuthentication.getUsername'); + extension + .addStrExpression( + 'UserID', + _('User ID'), + _('Get the unique user ID of the authenticated player.'), + '', + 'JsPlatform/Extensions/authentication.svg' + ) + .getCodeExtraInformation() + .setIncludeFile( + 'Extensions/PlayerAuthentication/playerauthenticationcomponents.js' + ) + .addIncludeFile( + 'Extensions/PlayerAuthentication/playerauthenticationtools.js' + ) + .setFunctionName('gdjs.playerAuthentication.getUserId'); + extension .addCondition( 'IsPlayerAuthenticated', diff --git a/Extensions/PlayerAuthentication/playerauthenticationtools.ts b/Extensions/PlayerAuthentication/playerauthenticationtools.ts index 547f704a93..a5f1e9c38b 100644 --- a/Extensions/PlayerAuthentication/playerauthenticationtools.ts +++ b/Extensions/PlayerAuthentication/playerauthenticationtools.ts @@ -171,7 +171,7 @@ namespace gdjs { if (!_checkedLocalStorage) { readAuthenticatedUserFromLocalStorage(); } - return _userId || null; + return _userId || ''; }; /**