Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
af9bf72a
Commit
af9bf72a
authored
Feb 17, 2022
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Session] add userId to session
parent
37a4d4d1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
Types.purs
src/Gargantext/Components/Login/Types.purs
+3
-1
Sessions.purs
src/Gargantext/Sessions.purs
+2
-2
Types.purs
src/Gargantext/Sessions/Types.purs
+6
-4
No files found.
src/Gargantext/Components/Login/Types.purs
View file @
af9bf72a
...
...
@@ -13,6 +13,7 @@ type Username = String
type Password = String
type Token = String
type TreeId = Int
type UserId = Int
newtype AuthRequest = AuthRequest
{ username :: Username
...
...
@@ -41,6 +42,7 @@ derive newtype instance JSON.WriteForeign AuthInvalid
newtype AuthData = AuthData
{ token :: Token
, tree_id :: TreeId
, user_id :: UserId
}
derive instance Generic AuthData _
derive instance Newtype AuthData _
...
...
@@ -50,5 +52,5 @@ derive newtype instance JSON.WriteForeign AuthData
instance Eq AuthData where
eq = genericEq
_AuthData :: Iso' AuthData { token :: Token, tree_id :: TreeId }
_AuthData :: Iso' AuthData { token :: Token, tree_id :: TreeId
, user_id :: UserId
}
_AuthData = iso (\(AuthData v) -> v) AuthData
src/Gargantext/Sessions.purs
View file @
af9bf72a
...
...
@@ -117,8 +117,8 @@ postAuthRequest backend ar@(AuthRequest {username}) =
decode (Left _err) = Left "Error when sending REST.post"
decode (Right (AuthResponse ar2))
| {inval: Just (AuthInvalid {message})} <- ar2 = Left message
| {valid: Just (AuthData {token, tree_id})} <- ar2 =
Right $ Session { backend, caches: Map.empty, token, treeId: tree_id, username }
| {valid: Just (AuthData {token, tree_id
, user_id
})} <- ar2 =
Right $ Session { backend, caches: Map.empty, token, treeId: tree_id, username
, userId: user_id
}
| otherwise = Left "Invalid response from server"
get :: forall a p. JSON.ReadForeign a => ToUrl Session p =>
...
...
src/Gargantext/Sessions/Types.purs
View file @
af9bf72a
...
...
@@ -6,6 +6,8 @@ module Gargantext.Sessions.Types
, cleanBackendUrl
) where
import Gargantext.Prelude
import Data.Array as A
import Data.Either (Either(..))
import Data.Eq.Generic (genericEq)
...
...
@@ -23,10 +25,9 @@ import Data.Show.Generic (genericShow)
import Data.String as DST
import Data.Tuple (Tuple)
import Foreign.Object as Object
import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Components.Login.Types (TreeId
, UserId
)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Ends (class ToUrl, Backend(..), backendUrl, sessionPath)
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute)
import Gargantext.Types (NodePath, SessionId(..), nodePath)
import Gargantext.Utils.JSON as GJSON
...
...
@@ -43,6 +44,7 @@ newtype Session = Session
, token :: String
, treeId :: TreeId
, username :: String
, userId :: UserId
}
------------------------------------------------------------------------
...
...
@@ -57,8 +59,8 @@ instance JSON.ReadForeign Session where
let rUp = r { caches = Map.fromFoldable (GUT.mapFst (fromMaybe 0 <<< Int.fromString) <$> objTuple) }
pure $ Session rUp
instance JSON.WriteForeign Session where
writeImpl (Session { backend, caches, token, treeId, username
}) =
JSON.writeImpl { backend, caches: caches', token, treeId, username }
writeImpl (Session { backend, caches, token, treeId, username
, userId
}) =
JSON.writeImpl { backend, caches: caches', token, treeId, username
, userId
}
where
caches' = JSON.writeImpl $ Object.fromFoldable (GUT.mapFst show <$> Map.toUnfoldable caches :: Array (Tuple String NT.CacheState))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment