get current member id

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

get current member id

Post by angus » 2020-10-20 14:41

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
AppGini 22.13

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: get current member id

Post by jsetzer » 2020-10-21 09:38

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 1776 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 */ });
    
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: get current member id

Post by angus » 2020-10-22 21:36

Jan,brilliant. look forward to the next release

Angus
AppGini 22.13

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: get current member id

Post by jsetzer » 2020-12-18 14:14

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/
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply