Page Startup Event - Get Current User

Is it possible to get the current user’s user id/name from within the Page Startup event? Without a reference to self or session, I’ve not been able to. Thanks.

page.session should still work (despite the somewhat misleading docstring) - from there, you can access whatever else you need from the session.

If you read really carefully in the docs you’ll find that there is indeed a session object attached to the page object provided. you can use this to get the current user:

# note that the session object is a direct child of the page object
# while accessing pageId or path requires a step into the props
# of page, ie: page.props.pageId
username = page.session.props.auth.user.username

So - I had tried this, but was seeing an empty user object:


However, this project (which is a simple test project on our new 8.1 demo server), had its Permissions set to ‘Public’ instead of ‘Authenticated’… which caused the user object to be empty. :man_facepalming:

Thanks guys.

1 Like

Correct - if the user isn’t logged in then there would be no user/username in place for the current Page.