login :: String -> AppM (User, Principal)
login token = do
    let url = "https://graph.facebook.com/me?access_token=" ++ token
    req <- buildReq url "GET" (Nothing :: Maybe ())
    fb <- httpJSON req
    agon <- ask
    fetchRes <- liftIO (runEitherT $ runAgonM (get $ fbID fb) agon)
    case fetchRes of
        Left err -> case (errHTTPCode err) of
            404 -> createUser fb
            _ -> lift $ left err
        Right u -> do
            p <- makePrincipal u
            return (u, p)
login :: String -> AppM (User, Principal)
login token = do
    let url = "https://graph.facebook.com/me?access_token=" ++ token
    req <- buildReq url "GET" (Nothing :: Maybe ())
    fb <- httpJSON req
    agon <- ask
    fetchRes <- liftIO (runEitherT $ runAgonM (get $ fbID fb) agon)
    case fetchRes of
        Left err -> case (errHTTPCode err) of
            404 -> createUser fb
            _ -> lift $ left err
        Right u -> do
            p <- makePrincipal u
            return (u, p)
login token = do
    let url = "https://graph.facebook.com/me?access_token=" ++ token
    req <- buildReq url "GET" (Nothing :: Maybe ())
    fb <- httpJSON req
    agon <- ask
    fetchRes <- liftIO (runEitherT $ runAgonM (get $ fbID fb) agon)
    case fetchRes of
        Left err -> case (errHTTPCode err) of
            404 -> createUser fb
            _ -> lift $ left err
        Right u -> do
            p <- makePrincipal u
            return (u, p)