Question

I wanted to display a message when user is redirected to Login page when not logged in.

Resource Authorization :

isAuthorized AdminR _ = isAdmin
isAuthorized _ _ = return Authorized

and

    isAdmin = do
            mu <- maybeAuthId
            return $ case mu of
                    Just "Foo" -> Authorized
                    Just _ -> Unauthorized "You are NOT a Admin !"
                    Nothing -> do
                                    setMessage "You have to Login "
                                    return AuthenticationRequired

Error:

Couldn't match type `m0 AuthResult' with `AuthResult'
Expected type: m0 () -> m0 AuthResult -> AuthResult
  Actual type: m0 () -> m0 AuthResult -> m0 AuthResult
In a stmt of a 'do' block: setMessage "You have to Login "
In the expression:
  do { setMessage "You have to Login ";
       return AuthenticationRequired }
In a case alternative:
    Nothing
      -> do { setMessage "You have to Login ";
              return AuthenticationRequired }

So, how to lift AuthResult from that Monad ?

Was it helpful?

Solution

Since you are running monad actions at the end of your case, you don't need to return the case.

isAdmin = do
   mu <- maybeAuthId
   case mu of
        Just "Foo" -> Authorized
        Just _ -> Unauthorized "You are NOT a Admin !"
        Nothing -> do
             setMessage "You have to Login "
             return AuthenticationRequired
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top