git.iko.soy/rowtype-yoga/purescript-supabase
on main help sign in
Add signin with options
commitcb37f980e7a6f3f4b2d3606e04c3ac14a9dc554b authorsigma-andex <77549848+sigma-andex@users.noreply.github.com> dateTue 4 Apr 2023, 10:19 (4 years ago) parent7a62189
2 files changed+21−5
src/Supabase/Supabase.js+3 src/Supabase/Supabase.purs+18−5
src/Supabase/Supabase.js+3
@@ -1,6 +1,9 @@
11export const signInWithOtpImpl = (supabase) => (email) => () =>
22 supabase.auth.signInWithOtp({ email });
33
4+export const signInWithOtpOptionsImpl = (supabase, email, options) =>
5+ supabase.auth.signInWithOtp({ email, options });
6+
47export const getSessionImpl = (supabase) => () => supabase.auth.getSession();
58export const onAuthStateChangeImpl = (supabase) => (handler) => () =>
69 supabase.auth.onAuthStateChange((_event, session) => handler(session));
src/Supabase/Supabase.purs+18−5
@@ -12,6 +12,7 @@ module Supabase.Supabase
1212 , ResultError
1313 , Session
1414 , SessionData
15+ , SignInOptions
1516 , StatusR
1617 , User
1718 , class Equals
@@ -21,13 +22,14 @@ module Supabase.Supabase
2122 , from
2223 , getSession
2324 , invoke
25+ , maybeSingle
2426 , onAuthStateChange
2527 , range
2628 , select
2729 , signInWithOtp
30+ , signInWithOtpOptions
2831 , signOut
2932 , single
30− , maybeSingle
3133 , update
3234 , upsert
3335 ) where
@@ -43,15 +45,16 @@ import Data.Nullable as Nullable
4345import Data.Tuple (Tuple(..))
4446import Effect (Effect)
4547import Effect.Aff (Aff, Error)
46−import Effect.Uncurried (EffectFn1, mkEffectFn1)
48+import Effect.Uncurried (EffectFn1, EffectFn3, mkEffectFn1, runEffectFn3)
4749import Fetch as Fetch
4850import Fetch.Core.Response as YogaJson.Core
4951import Fetch.Internal.Response as FetchInternalResponse
5052import Foreign (Foreign)
53+import Prim.Row (class Union)
5154import Supabase.Types (Client)
55+import Supabase.Util as Util
5256import Type.Function (type ($))
5357import Type.Row (type (+))
54−import Supabase.Util as Util
5558import Yoga.JSON (class ReadForeign, class WriteForeign, write) as YogaJson
5659import Yoga.JSON (class ReadForeign, class WriteForeign, writeImpl)
5760
@@ -139,13 +142,23 @@ range { from: f, to } = rangeImpl f to >>> Promise.toAffE >=> Util.fromJSON
139142
140143type InternalAuthResponse = { error :: Nullable Error }
141144
142−foreign import signInWithOtpImpl :: Client -> String -> Effect (Promise InternalAuthResponse)
143−
144145type AuthResponse = { error :: Maybe Error }
145146
147+foreign import signInWithOtpImpl :: Client -> String -> Effect (Promise InternalAuthResponse)
148+
146149signInWithOtp :: Client -> String -> Aff AuthResponse
147150signInWithOtp client email = signInWithOtpImpl client email # Promise.toAffE <#> \{ error } -> { error: Nullable.toMaybe error }
148151
152+type SignInOptions =
153+ ( shouldCreateUser :: Boolean
154+ , captchaToken :: String
155+ )
156+
157+foreign import signInWithOtpOptionsImpl :: forall options. EffectFn3 Client String options (Promise InternalAuthResponse)
158+
159+signInWithOtpOptions :: forall options thru. Union options thru SignInOptions => Client -> String -> { | options } -> Aff AuthResponse
160+signInWithOtpOptions client email options = runEffectFn3 signInWithOtpOptionsImpl client email options # Promise.toAffE <#> \{ error } -> { error: Nullable.toMaybe error }
161+
149162foreign import signOutImpl :: Client -> Effect (Promise Unit)
150163
151164signOut ∷ Client → Aff Unit