fix: login/signup flow working with session-based auth
- Fixed hashPasswordIO to use real PBKDF2 hashing from Sis.Auth - Added seed route (rseed) for demo data initialization - Replaced redirect() in update functions with success views (redirect uses throwError_ which broke with effectful 2.4) - Added loginSuccessView and signupSuccessView with dashboard links - Patched Hyperbole Socket.hs to parse WebSocket form body into Form params - Patched Hyperbole Wai.hs to include TargetViewId in response metadata - Fixed View/Page type mismatches (hyper wrapper vs plain view) - Removed dead pure after redirect calls - Verified: login submits, session set, success view rendered
This commit is contained in:
+7
-5
@@ -51,6 +51,10 @@ import System.FilePath (takeDirectory)
|
||||
import Text.Read (readMaybe)
|
||||
|
||||
import Sis.Types
|
||||
import Sis.Auth (hashPassword)
|
||||
import Crypto.Random.Entropy (getEntropy)
|
||||
import Data.ByteString.Base64 qualified as B64
|
||||
import Data.Text.Encoding qualified as TE
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Effect definition
|
||||
@@ -369,14 +373,12 @@ generateRecurringDates period startDate fromDate toDate = go (max startDate from
|
||||
next PeriodDaily = addDays 1; next PeriodWeekly = addDays 7; next PeriodMonthly = addGregorianMonthsClip 1
|
||||
|
||||
hashPasswordIO :: Text -> IO Text
|
||||
hashPasswordIO password = do
|
||||
-- Simple hashing stub — we'll use crypton via Auth.hs in the real implementation
|
||||
pure password
|
||||
hashPasswordIO = hashPassword
|
||||
|
||||
generateTokenIO :: IO Text
|
||||
generateTokenIO = do
|
||||
-- Simple token stub
|
||||
pure "dummy-token"
|
||||
bytes <- getEntropy 32
|
||||
pure $ TE.decodeUtf8 $ B64.encode bytes
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Database open helper
|
||||
|
||||
@@ -98,7 +98,7 @@ page = do
|
||||
case mSession of
|
||||
Nothing -> do
|
||||
redirect (routeUri RLogin)
|
||||
pure $ hyper ActivityPage $ el "Redirecting..."
|
||||
|
||||
Just us -> do
|
||||
hhs <- getUserHouseholds (UserId (usUserId us))
|
||||
case hhs of
|
||||
|
||||
@@ -95,7 +95,7 @@ page = do
|
||||
case mSession of
|
||||
Nothing -> do
|
||||
redirect (routeUri RLogin)
|
||||
pure $ hyper ChoresPage $ el "Redirecting..."
|
||||
|
||||
Just us -> do
|
||||
hhs <- getUserHouseholds (UserId (usUserId us))
|
||||
case hhs of
|
||||
|
||||
@@ -111,7 +111,7 @@ page = do
|
||||
case mSession of
|
||||
Nothing -> do
|
||||
redirect (routeUri RLogin)
|
||||
pure $ hyper DashboardPage $ el "Redirecting..."
|
||||
|
||||
Just us -> do
|
||||
today <- liftIO (utctDay <$> getCurrentTime)
|
||||
hhs <- getUserHouseholds (UserId (usUserId us))
|
||||
|
||||
@@ -120,7 +120,7 @@ page = do
|
||||
case mSession of
|
||||
Nothing -> do
|
||||
redirect (routeUri RLogin)
|
||||
pure $ hyper HouseholdPage $ el "Redirecting..."
|
||||
|
||||
Just us -> do
|
||||
hhs <- getUserHouseholds (UserId (usUserId us))
|
||||
case hhs of
|
||||
|
||||
+13
-4
@@ -41,10 +41,19 @@ instance (DB :> es, IOE :> es) => HyperView LoginPage es where
|
||||
Just u
|
||||
| verifyPassword (lfPassword formData') (userPasswordHash u) -> do
|
||||
saveSession (UserSession (unUserId (userId u)))
|
||||
redirect (routeUri RDashboard)
|
||||
pure $ hyper LoginPage $ el "Redirecting..."
|
||||
pure (loginSuccessView)
|
||||
|
||||
_ -> pure (loginView (Just "Invalid email or password"))
|
||||
update Noop = pure $ hyper LoginPage $ loginView Nothing
|
||||
update Noop = pure (loginView Nothing)
|
||||
|
||||
loginSuccessView :: View LoginPage ()
|
||||
loginSuccessView = do
|
||||
el @ att "class" nbContainerClass @ att "style" "max-width:480px;margin:4rem auto;text-align:center" $ do
|
||||
el @ att "class" nbBoxClass @ att "style" "padding:2rem" $ do
|
||||
el @ att "class" nbFontHeading1Class $ text "Logged In!"
|
||||
el @ att "style" "margin-top:1rem;margin-bottom:1rem" $ text "You are now logged in."
|
||||
route RDashboard $ text "Go to Dashboard"
|
||||
|
||||
loginView :: Maybe Text -> View LoginPage ()
|
||||
loginView mError = do
|
||||
el @ att "class" nbContainerClass @ att "style" "max-width:480px;margin:4rem auto" $ do
|
||||
@@ -71,5 +80,5 @@ page = do
|
||||
case mSession of
|
||||
Just _ -> do
|
||||
redirect (routeUri RDashboard)
|
||||
pure $ hyper LoginPage $ el "Redirecting..."
|
||||
|
||||
Nothing -> pure $ hyper LoginPage $ loginView Nothing
|
||||
|
||||
+11
-3
@@ -49,8 +49,16 @@ instance (DB :> es, IOE :> es) => HyperView SignupPage es where
|
||||
pwHash <- liftIO (hashPassword (sfPassword form))
|
||||
uid <- createUser (sfDisplayName form) (sfEmail form) pwHash
|
||||
saveSession (UserSession (unUserId uid))
|
||||
redirect (routeUri RDashboard)
|
||||
pure $ hyper SignupPage $ el "Redirecting..."
|
||||
pure (signupSuccessView)
|
||||
|
||||
signupSuccessView :: View SignupPage ()
|
||||
signupSuccessView = do
|
||||
el @ att "class" nbContainerClass @ att "style" "max-width:480px;margin:4rem auto;text-align:center" $ do
|
||||
el @ att "class" nbBoxClass @ att "style" "padding:2rem" $ do
|
||||
el @ att "class" nbFontHeading1Class $ text "Account Created!"
|
||||
el @ att "style" "margin-top:1rem;margin-bottom:1rem" $ text "Your account has been created."
|
||||
route RDashboard $ text "Go to Dashboard"
|
||||
|
||||
signupView :: Maybe Text -> View SignupPage ()
|
||||
signupView mError = do
|
||||
el @ att "class" nbContainerClass @ att "style" "max-width:480px;margin:4rem auto" $ do
|
||||
@@ -81,5 +89,5 @@ page = do
|
||||
case mSession of
|
||||
Just _ -> do
|
||||
redirect (routeUri RDashboard)
|
||||
pure $ hyper SignupPage $ el "Redirecting..."
|
||||
|
||||
Nothing -> pure $ hyper SignupPage $ signupView Nothing
|
||||
|
||||
@@ -14,6 +14,7 @@ data AppRoute
|
||||
| RChores
|
||||
| RHousehold
|
||||
| RActivity
|
||||
| RSeed
|
||||
deriving stock (Eq, Generic, Show)
|
||||
|
||||
instance Route AppRoute where
|
||||
|
||||
Reference in New Issue
Block a user