Skip to content

Commit

Permalink
Updated session docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jan 7, 2022
1 parent 26443fd commit a8e10c3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Guide/session.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,32 @@ action SessionExampleAction = do
setSession "userEmail" "hi@digitallyinduced.com"
```

Right now, [`setSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:setSession) only accepts `Text` values. Other types like `Int` have to be converted to `Text` using [`tshow theIntValue`](https://ihp.digitallyinduced.com/api-docs/IHP-Prelude.html#v:tshow).
You can use [`setSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:setSession) with other data types like `Int`, `Bool` or `UUID` as well:


```haskell
action SessionExampleAction = do
let meaningOfLife :: Int = 42
setSession "meaningOfLife" meaningOfLife
```

### Reading

You can use [`getSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSession) to retrieve a value:

```haskell
action SessionExampleAction = do
userEmail <- getSession "userEmail"
userEmail :: Maybe Text <- getSession "userEmail"
```

`userEmail` is set to `Just "hi@digitallyinduced.com"` when the value has been set before. Otherwise, it will be `Nothing`.

For convenience you can use [`getSessionInt`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSessionInt) to retrieve the value as a `Maybe Int`, and [`getSessionUUID`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSessionUUID) to retrieve the value as a `Maybe UUID`:
The [`getSession`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Session.html#v:getSession) also supports other data types like `Int`, `Bool` or `UUID`:

```haskell
action SessionExampleAction = do
counter :: Maybe Int <- getSessionInt "counter"
userId :: Maybe UUID <- getSessionUUID "userId"
counter :: Maybe Int <- getSession "counter"
userId :: Maybe UUID <- getSession "userId"
```

### Deleting
Expand Down

0 comments on commit a8e10c3

Please sign in to comment.