all repos

onasty @ babda7d

a one-time notes service

onasty/web/src/Auth.elm (view raw)

Smirnov Oleksandr Smirnov Oleksandr
ss2316544@gmail.com
refactor(web): make use of types for handling auth (#137)..., 11 months ago
1
module Auth exposing (User, onPageLoad, viewCustomPage)
2
3
import Auth.Action
4
import Auth.User
5
import Dict
6
import Route exposing (Route)
7
import Route.Path
8
import Shared
9
import View exposing (View)
10
11
12
type alias User =
13
    Auth.User.User
14
15
16
{-| Called before an auth-only page is loaded.
17
-}
18
onPageLoad : Shared.Model -> Route () -> Auth.Action.Action User
19
onPageLoad shared _ =
20
    case shared.user of
21
        Auth.User.NotSignedIn ->
22
            Auth.Action.pushRoute
23
                { path = Route.Path.Auth
24
                , query = Dict.empty
25
                , hash = Nothing
26
                }
27
28
        Auth.User.RefreshingTokens ->
29
            Auth.Action.loadCustomPage
30
31
        Auth.User.SignedIn credentials ->
32
            Auth.Action.loadPageWithUser credentials
33
34
35
{-| Renders whenever `Auth.Action.loadCustomPage` is returned from `onPageLoad`.
36
-}
37
viewCustomPage : Shared.Model -> Route () -> View Never
38
viewCustomPage _ _ =
39
    View.fromString "Loading..."