Page 1 of 1

get current member id

Posted: 2020-10-20 14:41
by angus
Hi, is there a way to get the current user with the Javascript helper?

I have built some filters and want to add the current user to the filter

Re: get current member id

Posted: 2020-10-21 09:38
by jsetzer
AppGini Helper Javascript Library
In NEXT version there will be a function for this:

Code: Select all

AppGiniHelper.getMemberID( function(memberID) { /* your code */ } );
Solution in standard AppGini

There are different ways to get it. I think the easiest would be:

Code: Select all

<!-- file: hooks/header-extras.php -->
<script>
  const currentMemberID = '<?=getLoggedMemberID()?>';
</script>
Then you can use the variable currentMemberID in your javascript:

Code: Select all

// file: hooks/TABLENAME-dv.js
$j(document).ready(function(){
    alert('Your are logged in as: ' + currentMemberID);
});
chrome_pZuL2pfIir.png
chrome_pZuL2pfIir.png (4.45 KiB) Viewed 3643 times

Pros
  • Easy to integrate
Cons
  • Will not be updated after session timeout
    Usually you will be redirected to login page automatically after 60 seconds. But in between the currentMemberID will still hold the old value which was valid when page was loaded, but is invalid since session timeout. If you need to react to such changes you should use AJAX before every relevant action and fetch the current user from the server:

    Code: Select all

    // not tested
    jQuery.get('ajax_check_login.php', function(response) { /* your code here, for example disable buttons */ });
    

Re: get current member id

Posted: 2020-10-22 21:36
by angus
Jan,brilliant. look forward to the next release

Angus

Re: get current member id

Posted: 2020-12-18 14:14
by jsetzer
this function has been rolled out with 2020/10 version.

See docs at the bottom of this page:
https://appgini.bizzworxx.de/products/j ... functions/