MyNixOS website logo
Description

Utilities to split reflex app to authorized and not authorized contexts.

The package provides utilities to build in authorization in reflex application in agnostic way to the concrete authorization scheme.

reflex-monad-auth

The package provides utilities to build in authorization in reflex application in agnostic way to the concrete authorization scheme.

Features:

  • Split application into two contexts: authorized and not authorized. Provides helpers to dynamically switch between both.
  • Access to authorization specific state in authorized part of FRP network.

How to use

See (example)[./example/Main.hs] and run it with cabal new-run -f examples.

First, define you own authorization type:

data JWTAuth = JWTAuth {
    authToken :: !Text
  , authRole  :: !Role
  } deriving (Eq)

Use it in info type hole in AuthT monad transformer:

runAuthJWT :: (Reflex t, TriggerEvent t m, MonadIO m) => AuthT JWTAuth t m a -> m a
runAuthJWT = runAuth

main :: IO ()
main = mainWidgetWithCss css $ runAuthJWT frontend

Now you can use the main tool of the package liftAuth:

frontend :: (HasAuth t m, PerformEvent t m, TriggerEvent t m, MonadHold t m, DomBuilder t m, PostBuild t m, MonadIO m, MonadIO (Performable m), AuthInfo t m ~ JWTAuth) => m ()
frontend = void $ liftAuth notlogged logged
  where
    notlogged = do
      pressE <- buttonClass "outline" "Login"
      widgetHold_ (pure ()) $ text "Logging in..." <$ pressE
      signE <- delay 1 pressE
      loginE <- requestLoginFromServer signE -- Here you widget that ask server for token
      void $ signin loginE
    logged = do
      pressE <- buttonClass "outline" "Logout"
      text "We are authorized!"
      void $ signout pressE

Hacking

To enter shell with all dependencies for GHC, use ./ghc.sh script. Or use ./ghcjs.sh for GHCJS.

Metadata

Version

0.1.0.1

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows