Pode icon indicating copy to clipboard operation
Pode copied to clipboard

Custom session storage middleware documentation incorrect

Open Szeraax opened this issue 2 years ago • 0 comments

Describe the Change

The tutorial on Sessions gives a suggestion on how to write a custom storage provider with Redis. It suggests that you convert from JSON to Hashtable (ConvertFrom-Json -AsHashTable). However, it doesn't call out that the Data.Auth.User object actually NEEDS to be an object in order for the user session to work properly (such as displaying the username in the header of the site).

https://github.com/Badgerati/Pode/blob/develop/docs/Tutorials/Middleware/Types/Sessions.md#storage

I wrote my own in-memory provider and it worked fine. But when trying to roundtrip to JSON in Azure Tables or even in my in-memory provider (both with -AsHashTable), the session would work but the username wouldn't appear in the app header.

From this code, I determined the cause:

try {
        $s.Data.Data.GetType() | Out-Default
        $s.Data.Data.Auth.GetType() | Out-Default
        $s.Data.Data.Auth.User.GetType() | Out-Default
    }
    catch {}

image

Additional Context

I would suggest editing the example and adding a paragraph about how the User property in the hashtable MUST be a PSObject. I will go file a PR as a first pass.

Workaround

I am able to get my project working via: $s.Data.Data.Auth.User = [PSCustomObject]$s.Data.Data.Auth.User

Szeraax avatar Jan 09 '24 07:01 Szeraax