@niledatabase/react 5.3.3-alpha.2 → 5.3.3-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +49 -66
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import se from"react";import{useForm as Zo}from"react-hook-form";import{Mail as Jo}from"lucide-react";import*as y from"react";import{Slot as qo}from"@radix-ui/react-slot";import{Controller as jo,FormProvider as Wo,useFormContext as tt}from"react-hook-form";import{useQuery as Rt}from"@tanstack/react-query";import{clsx as zo}from"clsx";import{twMerge as Oo}from"tailwind-merge";import{auth as Te}from"@niledatabase/client";import Ze,{useContext as zt,useRef as Lo,useState as To}from"react";import{QueryClient as Ut,QueryClientContext as Ot,QueryClientProvider as Uo}from"@tanstack/react-query";function z(e){let t=zt(Ot),[o]=To(()=>e||t?null:new Ut),r=Lo(null);return e||t||o||(r.current||(r.current=new Ut),r.current)}function Q({client:e,children:t}){let o=zt(Ot),r=z(e);return!e&&o?Ze.createElement(Ze.Fragment,null,t):Ze.createElement(Uo,{client:r},t)}function f(...e){return Oo(zo(e))}function Ro(...e){let t=new Headers;for(let o of e)o&&new Headers(o).forEach((r,n)=>{t.set(n,r)});return t}function we(e,t={},o){let r,n,i={};if(t&&typeof t=="object"){let u=t;"init"in u&&u.init&&typeof u.init=="object"&&(r=u.init),"auth"in u&&u.auth&&typeof u.auth=="object"&&(n=u.auth);let c=new Set(["init","auth","baseUrl","basePath","fetchUrl","client","user","tenants","disableQuery","onError","onSuccess","beforeMutate","onTenantChange","activeTenant","useCookie","className","emptyText","buttonText","profilePicturePlaceholder"]);for(let[d,g]of Object.entries(u))!c.has(d)&&g!==void 0&&(i[d]=g)}let s={...o?.auth?.requestInit??{},...o?.init??{},...n?.requestInit??{},...r??{},...i,headers:Ro({"content-type":"application/json; charset=UTF-8"},o?.auth?.requestInit?.headers,o?.init?.headers,n?.requestInit?.headers,r?.headers,i.headers)},a=e;if(!(!!o?.fetchUrl||!!(t&&typeof t=="object"&&"fetchUrl"in t&&t.fetchUrl))&&e.startsWith("/")){let u=n??o?.auth,c=Ho(o,t,u);a=`${Ao(o,t,u)}${c}${e}`}return fetch(a,s)}var Ao=(e,t={},o)=>e?.baseUrl?e.baseUrl:"baseUrl"in t&&t.baseUrl?t.baseUrl:o?.state?.baseUrl?o.state.baseUrl:Te.state.baseUrl?Te.state.baseUrl:"",Ho=(e,t={},o)=>e?.basePath?e.basePath:"basePath"in t&&t.basePath?t.basePath:o?.state?.basePath?o.state.basePath:Te.state.basePath?Te.state.basePath:"";function At(e){let{baseUrl:t="",basePath:o="/api",disableQuery:r,init:n,client:i,providersUrl:s,csrfUrl:a}=e??{},l=z(i);Rt({queryKey:["providers",t,o,s],queryFn:async()=>{let u=await fetch(s??`${t}${o}/auth/providers`,n);if(!u.ok)throw new Error(`Failed to fetch providers (${u.status})`);return await u.json()},enabled:r!==!0},l),Ue({baseUrl:t,basePath:o,disableQuery:r,init:n,client:i,csrfUrl:a})}function Ue(e){let{baseUrl:t="",basePath:o="/api",disableQuery:r,init:n,client:i,csrfUrl:s}=e??{},a=z(i);Rt({queryKey:["csrf",t,o,s],queryFn:async()=>{let l=await fetch(s??`${t}${o}/auth/csrf`,n);if(!l.ok)throw new Error(`Failed to fetch CSRF token (${l.status})`);return await l.json()},enabled:r!==!0},a)}import*as ze from"react";import*as Je from"@radix-ui/react-label";import{cva as Vo}from"class-variance-authority";var Qo=Vo("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),et=ze.forwardRef(({className:e,...t},o)=>ze.createElement(Je.Root,{ref:o,className:f(Qo(),e),...t}));et.displayName=Je.Root.displayName;import*as Oe from"react";var j=Oe.forwardRef(({className:e,type:t,...o},r)=>Oe.createElement("input",{type:t,className:f("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...o}));j.displayName="Input";var W=Wo,Ht=y.createContext({}),ge=({...e})=>y.createElement(Ht.Provider,{value:{name:e.name}},y.createElement(jo,{...e})),Re=()=>{let e=y.useContext(Ht),t=y.useContext(Vt),{getFieldState:o,formState:r}=tt(),n=o(e.name,r);if(!e)throw new Error("useFormField should be used within <FormField>");let{id:i}=t;return{id:i,name:e.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...n}},Vt=y.createContext({}),oe=y.forwardRef(({className:e,...t},o)=>{let r=y.useId();return y.createElement(Vt.Provider,{value:{id:r}},y.createElement("div",{ref:o,className:f("py-2",e),...t}))});oe.displayName="FormItem";var re=y.forwardRef(({className:e,...t},o)=>{let{error:r,formItemId:n}=Re();return y.createElement(et,{ref:o,className:f(r&&"text-destructive",e),htmlFor:n,...t})});re.displayName="FormLabel";var ne=y.forwardRef(({...e},t)=>{let{error:o,formItemId:r,formDescriptionId:n,formMessageId:i}=Re();return y.createElement(qo,{ref:t,id:r,"aria-describedby":o?`${n} ${i}`:`${n}`,"aria-invalid":!!o,...e})});ne.displayName="FormControl";var he=y.forwardRef(({className:e,...t},o)=>{let{formDescriptionId:r}=Re();return y.createElement("p",{ref:o,id:r,className:f("text-sm text-muted-foreground",e),...t})});he.displayName="FormDescription";var ye=y.forwardRef(({className:e,children:t,...o},r)=>{let{error:n,formMessageId:i}=Re(),s=n?String(n?.message):t;return s?y.createElement("p",{ref:r,id:i,className:f("text-sm font-medium text-destructive",e),...o},s):null});ye.displayName="FormMessage";var Z=({hide:e})=>{let t=tt();return y.createElement(ge,{control:t.control,name:"email",render:({field:o})=>e?y.createElement("input",{type:"hidden",...o}):y.createElement(oe,null,y.createElement(re,null,"Email"),y.createElement(ne,null,y.createElement(j,{placeholder:"Email",...o,type:"email","aria-label":o.name,autoComplete:"email",required:!0})),y.createElement(he,null,"Your email address"),y.createElement(ye,null))})},be=({autoComplete:e="current-password"}={})=>{let t=tt();return y.createElement(ge,{control:t.control,name:"password",render:({field:o})=>y.createElement(oe,null,y.createElement(re,null,"Password"),y.createElement(ne,null,y.createElement(j,{placeholder:"Password",...o,type:"password","aria-label":o.name,autoComplete:e,required:!0})),y.createElement(he,null,"The desired password"),y.createElement(ye,null))})};import*as J from"react";import{Slottable as $o,Slot as Ko}from"@radix-ui/react-slot";import{cva as Go}from"class-variance-authority";import{Loader2 as _o}from"lucide-react";var ie=Go("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 gap-1",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),E=J.forwardRef(({asChild:e=!1,children:t,className:o,disabled:r,loading:n,size:i,variant:s,...a},l)=>J.createElement(e?Ko:"button",{className:f(ie({variant:s,size:i,className:o})),ref:l,disabled:n||r,...a},J.createElement($o,null,n?J.createElement("div",{className:"relative flex items-center justify-center"},J.createElement("div",{className:"absolute"},J.createElement(_o,{className:"animate-spin"})),J.createElement("span",{className:"opacity-0"},t)):t)));E.displayName="Button";import{useMutation as Xo}from"@tanstack/react-query";import{signIn as Yo}from"@niledatabase/client";function ot(e){let{onSuccess:t,onError:o,beforeMutate:r,callbackUrl:n,redirect:i=!1,init:s,client:a}=e??{},l=z(a);return Xo({mutationFn:async u=>{let c={...u,callbackUrl:n,redirect:i},g=(r&&r(c))??c,m=await Yo("email",{init:s,...g});if(i===!1&&!m||m&&(!m.ok||m.error))throw new Error(m?.error??"Email sign in failed");return m},onSuccess:t,onError:o},l)}function Qt(e){return ot(e).mutate}function rt(e){let{client:t}=e??{};return se.createElement(Q,{client:t},se.createElement(er,{...e}))}function er(e){let t=ot(e),o=Zo({defaultValues:{email:""}});return se.createElement(W,{...o},se.createElement("form",{onSubmit:o.handleSubmit(({email:r})=>t.mutate({email:r})),className:"space-y-8"},se.createElement(Z,null),!e.onError&&t.error?se.createElement("p",{role:"alert",className:"text-sm font-medium text-destructive"},t.error instanceof Error?t.error.message:"Email sign in failed"):null,se.createElement(E,{type:"submit",className:"flex flex-row gap-2",loading:t.isPending},se.createElement(Jo,{"aria-hidden":"true"}),e.buttonText??"Sign in with email")))}import{Slot as tr}from"@radix-ui/react-slot";import nt from"react";import{Mail as or}from"lucide-react";import{signIn as rr}from"@niledatabase/client";var qt=({callbackUrl:e,className:t,variant:o,size:r,asChild:n=!1,redirect:i=!1,buttonText:s="Continue with Email",email:a,onFailure:l,onSent:u,fetchUrl:c,baseUrl:d,auth:g,init:m,loading:p,type:v="button",onClick:M,children:F,...x})=>nt.createElement(n?tr:"button",{...x,...n?{}:{type:v},className:f(ie({variant:o,size:r,className:t})),"data-slot":"email-signin-button",onClick:async S=>{let N=await rr("email",{email:a,callbackUrl:e,redirect:i,fetchUrl:c,baseUrl:d,auth:g,init:m});M?.(S,N),i===!1&&!N||N&&(!N.ok||N.error)?l?.(N):u?.()}},F||nt.createElement("div",{className:"flex flex-row gap-2 items-center"},nt.createElement(or,{"aria-hidden":"true"}),s));qt.displayName="EmailSignInButton";var jt=qt;import G from"react";import _ from"react";import{Slot as nr,Slottable as ir}from"@radix-ui/react-slot";import{Loader2 as sr}from"lucide-react";import{signIn as ar}from"@niledatabase/client";function R({provider:e,dataSlot:t,defaultButtonText:o,providerClassName:r,icon:n,renderDefaultContent:i,callbackUrl:s,className:a,buttonText:l=o,variant:u,size:c,init:d,auth:g,fetchUrl:m,baseUrl:p,onClick:v,asChild:M=!1,loading:F=!1,disabled:x,type:B="button",children:S,...N}){let L=M&&_.isValidElement(S),I=async H=>{if(F||x){H.preventDefault();return}let Y=await ar(e,{callbackUrl:s,init:d,auth:g,fetchUrl:m,baseUrl:p});v?.(H,Y)},X=i?i(l,n):_.createElement(_.Fragment,null,n,l),pe=()=>{let H=S??X;return F?_.createElement("span",{className:"relative inline-flex items-center justify-center"},_.createElement("span",{className:"absolute"},_.createElement(sr,{className:"animate-spin","aria-hidden":"true"})),_.createElement("span",{className:"opacity-0 inline-flex items-center gap-4"},H)):H};return L?_.createElement(nr,{...N,"aria-disabled":F||x||void 0,"data-slot":t,className:f(ie({variant:u,size:c,className:a}),r),onClick:I},n,_.createElement(ir,null,S)):_.createElement("button",{...N,type:B,disabled:F||x,"data-slot":t,className:f(ie({variant:u,size:c,className:a}),r),onClick:I},pe())}var Wt=e=>G.createElement(R,{provider:"google",dataSlot:"google-button",defaultButtonText:"Continue with Google",providerClassName:"bg-[#4285f4] hover:bg-[#4285f4] hover:bg-opacity-85 pl-[3px] text-white",icon:G.createElement(lr,null),renderDefaultContent:(t,o)=>G.createElement("div",{className:"inline-flex items-center flex-1 justify-between font-roboto rounded-[4px] gap-4 google-logo"},G.createElement("div",{style:{background:"white",borderRadius:"4px",padding:"0.5rem"}},o),t),...e});Wt.displayName="GoogleSSOButton";var $t=Wt;function lr(){return G.createElement("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18"},G.createElement("g",{fill:"#000",fillRule:"evenodd"},G.createElement("path",{d:"M9 3.48c1.69 0 2.83.73 3.48 1.34l2.54-2.48C13.46.89 11.43 0 9 0 5.48 0 2.44 2.02.96 4.96l2.91 2.26C4.6 5.05 6.62 3.48 9 3.48z",fill:"#EA4335"}),G.createElement("path",{d:"M17.64 9.2c0-.74-.06-1.28-.19-1.84H9v3.34h4.96c-.1.83-.64 2.08-1.84 2.92l2.84 2.2c1.7-1.57 2.68-3.88 2.68-6.62z",fill:"#4285F4"}),G.createElement("path",{d:"M3.88 10.78A5.54 5.54 0 0 1 3.58 9c0-.62.11-1.22.29-1.78L.96 4.96A9.008 9.008 0 0 0 0 9c0 1.45.35 2.82.96 4.04l2.92-2.26z",fill:"#FBBC05"}),G.createElement("path",{d:"M9 18c2.43 0 4.47-.8 5.96-2.18l-2.84-2.2c-.76.53-1.78.9-3.12.9-2.38 0-4.4-1.57-5.12-3.74L.97 13.04C2.45 15.98 5.48 18 9 18z",fill:"#34A853"}),G.createElement("path",{fill:"none",d:"M0 0h18v18H0z"})))}import ae from"react";var Kt=e=>ae.createElement(R,{provider:"azure-ad",dataSlot:"azure-button",defaultButtonText:"Continue with Microsoft",providerClassName:"bg-[#0078d4] hover:bg-[#0078d4] hover:bg-opacity-85 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:ae.createElement(mr,null),...e});Kt.displayName="AzureSignInButton";var ur=Kt,mr=()=>ae.createElement("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 23 23",className:"w-5 h-5 ml-3"},ae.createElement("path",{fill:"#f3f3f3",d:"M0 0h23v23H0z"}),ae.createElement("path",{fill:"#f35325",d:"M1 1h10v10H1z"}),ae.createElement("path",{fill:"#81bc06",d:"M12 1h10v10H12z"}),ae.createElement("path",{fill:"#05a6f0",d:"M1 12h10v10H1z"}),ae.createElement("path",{fill:"#ffba08",d:"M12 12h10v10H12z"}));import xe from"react";var Gt=e=>xe.createElement(R,{provider:"discord",dataSlot:"discord-button",defaultButtonText:"Continue with Discord",providerClassName:"bg-[#5865F2] hover:bg-[#5865F2] hover:bg-opacity-85 pl-[3px] gap-4 transition-colors border shadow-md text-white",icon:xe.createElement(dr,null),...e});Gt.displayName="DiscordSignInButton";var cr=Gt,dr=()=>xe.createElement("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"0 0 75 59",version:"1.1",xmlns:"http://www.w3.org/2000/svg"},xe.createElement("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd"},xe.createElement("g",{id:"discord-icon",transform:"translate(2.000000, 2.411745)",fillRule:"nonzero",stroke:"#636262",strokeWidth:"0"},xe.createElement("path",{d:"M60.1044999,4.48605546 C55.5791999,2.40965546 50.7264999,0.879855461 45.6526999,0.00367546142 C45.5602999,-0.0132345386 45.4679999,0.0290244614 45.4203999,0.113544461 C44.7962999,1.22355546 44.1049999,2.67165546 43.6208999,3.80985546 C38.1636999,2.99285546 32.7344999,2.99285546 27.3891999,3.80985546 C26.9049999,2.64635546 26.1885999,1.22355546 25.5616999,0.113544461 C25.5140999,0.0318444614 25.4217999,-0.0104145386 25.3293999,0.00367546142 C20.2583999,0.877055461 15.4056999,2.40685546 10.8775999,4.48605546 C10.8383999,4.50295546 10.8047999,4.53115546 10.7824999,4.56775546 C1.57794989,18.3191555 -0.94356111,31.7325555 0.29340789,44.9796555 C0.29900489,45.0444555 0.33538589,45.1064555 0.38576089,45.1458555 C6.45865989,49.6056555 12.3412999,52.3131555 18.1146999,54.1077555 C18.2070999,54.1359555 18.3049999,54.1021555 18.3637999,54.0260555 C19.7294999,52.1610555 20.9468999,50.1945555 21.9906999,48.1265555 C22.0522999,48.0054555 21.9934999,47.8617555 21.8675999,47.8138555 C19.9365999,47.0813555 18.0978999,46.1882555 16.3291999,45.1740555 C16.1892999,45.0923555 16.1780999,44.8922555 16.3067999,44.7964555 C16.6789999,44.5175555 17.0512999,44.2273555 17.4066999,43.9343555 C17.4709999,43.8808555 17.5605999,43.8695555 17.6361999,43.9033555 C29.2557999,49.2084555 41.8353999,49.2084555 53.3178999,43.9033555 C53.3934999,43.8667555 53.4830999,43.8780555 53.5501999,43.9315555 C53.9056999,44.2245555 54.2778999,44.5175555 54.6528999,44.7964555 C54.7815999,44.8922555 54.7731999,45.0923555 54.6332999,45.1740555 C52.8645999,46.2079555 51.0258999,47.0813555 49.0920999,47.8110555 C48.9661999,47.8589555 48.9101999,48.0054555 48.9717999,48.1265555 C50.0379999,50.1916555 51.2553999,52.1581555 52.5958999,54.0232555 C52.6518999,54.1021555 52.7525999,54.1359555 52.8449999,54.1077555 C58.6463999,52.3131555 64.5289999,49.6056555 70.6018999,45.1458555 C70.6550999,45.1064555 70.6886999,45.0472555 70.6942999,44.9824555 C72.1746999,29.6673555 68.2146999,16.3639555 60.1967999,4.57055546 C60.1771999,4.53115546 60.1436999,4.50295546 60.1044999,4.48605546 Z M23.7258999,36.9135555 C20.2275999,36.9135555 17.3450999,33.7018555 17.3450999,29.7575555 C17.3450999,25.8132555 20.1716999,22.6015555 23.7258999,22.6015555 C27.3079999,22.6015555 30.1625999,25.8414555 30.1065999,29.7575555 C30.1065999,33.7018555 27.2799999,36.9135555 23.7258999,36.9135555 Z M47.3177999,36.9135555 C43.8195999,36.9135555 40.9370999,33.7018555 40.9370999,29.7575555 C40.9370999,25.8132555 43.7635999,22.6015555 47.3177999,22.6015555 C50.8999999,22.6015555 53.7544999,25.8414555 53.6985999,29.7575555 C53.6985999,33.7018555 50.8999999,36.9135555 47.3177999,36.9135555 Z",id:"Shape",fill:"white"}))));import Ae from"react";var _t=e=>Ae.createElement(R,{provider:"github",dataSlot:"github-button",defaultButtonText:"Continue with GitHub",providerClassName:"bg-black hover:bg-slate-800 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:Ae.createElement(pr,null),...e});_t.displayName="GitHubSignInButton";var fr=_t,pr=()=>Ae.createElement("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32.58 31.77",fill:"currentColor",className:"w-5 h-5 ml-3"},Ae.createElement("path",{fill:"#FFFFFF",d:"M16.29,0a16.29,16.29,0,0,0-5.15,31.75c.82.15,1.11-.36,1.11-.79s0-1.41,0-2.77C7.7,29.18,6.74,26,6.74,26a4.36,4.36,0,0,0-1.81-2.39c-1.47-1,.12-1,.12-1a3.43,3.43,0,0,1,2.49,1.68,3.48,3.48,0,0,0,4.74,1.36,3.46,3.46,0,0,1,1-2.18c-3.62-.41-7.42-1.81-7.42-8a6.3,6.3,0,0,1,1.67-4.37,5.94,5.94,0,0,1,.16-4.31s1.37-.44,4.48,1.67a15.41,15.41,0,0,1,8.16,0c3.11-2.11,4.47-1.67,4.47-1.67A5.91,5.91,0,0,1,25,11.07a6.3,6.3,0,0,1,1.67,4.37c0,6.26-3.81,7.63-7.44,8a3.85,3.85,0,0,1,1.11,3c0,2.18,0,3.94,0,4.47s.29.94,1.12.78A16.29,16.29,0,0,0,16.29,0Z"}));import He from"react";var Xt=e=>He.createElement(R,{provider:"hubspot",dataSlot:"hubspot-button",defaultButtonText:"Continue with HubSpot",providerClassName:"bg-[#ff7a59] hover:bg-[#ff7a59] hover:bg-opacity-85 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:He.createElement(hr,null),...e});Xt.displayName="HubSpotSignInButton";var gr=Xt,hr=()=>He.createElement("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"6.20856283 .64498824 244.26943717 251.24701176",xmlns:"http://www.w3.org/2000/svg"},He.createElement("path",{d:"m191.385 85.694v-29.506a22.722 22.722 0 0 0 13.101-20.48v-.677c0-12.549-10.173-22.722-22.721-22.722h-.678c-12.549 0-22.722 10.173-22.722 22.722v.677a22.722 22.722 0 0 0 13.101 20.48v29.506a64.342 64.342 0 0 0 -30.594 13.47l-80.922-63.03c.577-2.083.878-4.225.912-6.375a25.6 25.6 0 1 0 -25.633 25.55 25.323 25.323 0 0 0 12.607-3.43l79.685 62.007c-14.65 22.131-14.258 50.974.987 72.7l-24.236 24.243c-1.96-.626-4-.959-6.057-.987-11.607.01-21.01 9.423-21.007 21.03.003 11.606 9.412 21.014 21.018 21.017 11.607.003 21.02-9.4 21.03-21.007a20.747 20.747 0 0 0 -.988-6.056l23.976-23.985c21.423 16.492 50.846 17.913 73.759 3.562 22.912-14.352 34.475-41.446 28.985-67.918-5.49-26.473-26.873-46.734-53.603-50.792m-9.938 97.044a33.17 33.17 0 1 1 0-66.316c17.85.625 32 15.272 32.01 33.134.008 17.86-14.127 32.522-31.977 33.165",fill:"white"}));import Pe from"react";var Yt=e=>Pe.createElement(R,{provider:"linkedin",dataSlot:"linkedin-button",defaultButtonText:"Continue with LinkedIn",providerClassName:"bg-[#0288D1] hover:bg-[#0288D1] pl-[3px] hover:bg-opacity-85 gap-4 transition-colors shadow-md text-white",icon:Pe.createElement(br,null),...e});Yt.displayName="LinkedInSignInButton";var yr=Yt,br=()=>Pe.createElement("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",className:"w-6 h-6 ml-3"},Pe.createElement("path",{fill:"#fff",d:"M42,37c0,2.762-2.238,5-5,5H11c-2.761,0-5-2.238-5-5V11c0-2.762,2.239-5,5-5h26c2.762,0,5,2.238,5,5V37z"}),Pe.createElement("path",{fill:"#0288D1",d:"M12 19H17V36H12zM14.485 17h-.028C12.965 17 12 15.888 12 14.499 12 13.08 12.995 12 14.514 12c1.521 0 2.458 1.08 2.486 2.499C17 15.887 16.035 17 14.485 17zM36 36h-5v-9.099c0-2.198-1.225-3.698-3.192-3.698-1.501 0-2.313 1.012-2.707 1.99C24.957 25.543 25 26.511 25 27v9h-5V19h5v2.616C25.721 20.5 26.85 19 29.738 19c3.578 0 6.261 2.25 6.261 7.274L36 36 36 36z"}));import le from"react";var Zt=e=>le.createElement(R,{provider:"slack",dataSlot:"slack-button",defaultButtonText:"Continue with Slack",providerClassName:"bg-[#4A154B] pl-[3px] hover:bg-opacity-85 gap-4 transition-colors shadow-md text-white",icon:le.createElement(wr,null),...e});Zt.displayName="SlackSignInButton";var vr=Zt,wr=()=>le.createElement("svg",{"aria-hidden":"true",focusable:"false",enableBackground:"new 0 0 2447.6 2452.5",viewBox:"0 0 2447.6 2452.5",className:"w-5 h-5 ml-3",xmlns:"http://www.w3.org/2000/svg"},le.createElement("g",{clipRule:"evenodd",fillRule:"evenodd"},le.createElement("path",{d:"m897.4 0c-135.3.1-244.8 109.9-244.7 245.2-.1 135.3 109.5 245.1 244.8 245.2h244.8v-245.1c.1-135.3-109.5-245.1-244.9-245.3.1 0 .1 0 0 0m0 654h-652.6c-135.3.1-244.9 109.9-244.8 245.2-.2 135.3 109.4 245.1 244.7 245.3h652.7c135.3-.1 244.9-109.9 244.8-245.2.1-135.4-109.5-245.2-244.8-245.3z",fill:"#36c5f0"}),le.createElement("path",{d:"m2447.6 899.2c.1-135.3-109.5-245.1-244.8-245.2-135.3.1-244.9 109.9-244.8 245.2v245.3h244.8c135.3-.1 244.9-109.9 244.8-245.3zm-652.7 0v-654c.1-135.2-109.4-245-244.7-245.2-135.3.1-244.9 109.9-244.8 245.2v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.3z",fill:"#2eb67d"}),le.createElement("path",{d:"m1550.1 2452.5c135.3-.1 244.9-109.9 244.8-245.2.1-135.3-109.5-245.1-244.8-245.2h-244.8v245.2c-.1 135.2 109.5 245 244.8 245.2zm0-654.1h652.7c135.3-.1 244.9-109.9 244.8-245.2.2-135.3-109.4-245.1-244.7-245.3h-652.7c-135.3.1-244.9 109.9-244.8 245.2-.1 135.4 109.4 245.2 244.7 245.3z",fill:"#ecb22e"}),le.createElement("path",{d:"m0 1553.2c-.1 135.3 109.5 245.1 244.8 245.2 135.3-.1 244.9-109.9 244.8-245.2v-245.2h-244.8c-135.3.1-244.9 109.9-244.8 245.2zm652.7 0v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.2v-653.9c.2-135.3-109.4-245.1-244.7-245.3-135.4 0-244.9 109.8-244.8 245.1 0 0 0 .1 0 0",fill:"#e01e5a"})));import Ve from"react";var Jt=e=>Ve.createElement(R,{provider:"twitter",dataSlot:"twitter-button",defaultButtonText:"Continue with X",providerClassName:"bg-black hover:bg-slate-800 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:Ve.createElement(Sr,null),...e});Jt.displayName="XSignInButton";var xr=Jt,Sr=()=>Ve.createElement("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"0 0 24 24",version:"1.1"},Ve.createElement("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",fill:"#ffffff"}));import Ce from"react";var eo=e=>Ce.createElement(R,{provider:"okta",dataSlot:"okta-button",defaultButtonText:"Continue with Okta",providerClassName:"bg-[#181818] hover:bg-[#3f59e4] pl-[3px] gap-4 transition-colors shadow-md text-white",icon:Ce.createElement(Cr,null),...e});eo.displayName="OktaSignInButton";var Pr=eo,Cr=()=>Ce.createElement("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 63 63",fill:"currentColor",className:"w-5 h-5 ml-3",width:"18",height:"18"},Ce.createElement("g",null,Ce.createElement("path",{d:`M34.6,0.4l-1.3,16c-0.6-0.1-1.2-0.1-1.9-0.1c-0.8,0-1.6,0.1-2.3,0.2l-0.7-7.7c0-0.2,0.2-0.5,0.4-0.5h1.3
|
|
2
|
+
import{useForm as Pn}from"react-hook-form";import{Mail as Cn}from"lucide-react";import*as H from"react";import{Slot as dn}from"@radix-ui/react-slot";import{Controller as fn,FormProvider as pn,useFormContext as st}from"react-hook-form";import{useQuery as Qt}from"@tanstack/react-query";import{clsx as on}from"clsx";import{twMerge as nn}from"tailwind-merge";import{auth as He}from"@niledatabase/client";import{useContext as Ht,useRef as Jo,useState as jo}from"react";import{QueryClient as Ot,QueryClientContext as Vt,QueryClientProvider as en}from"@tanstack/react-query";import{Fragment as tn,jsx as At}from"react/jsx-runtime";function B(e){let t=Ht(Vt),[o]=jo(()=>e||t?null:new Ot),n=Jo(null);return e||t||o||(n.current||(n.current=new Ot),n.current)}function U({client:e,children:t}){let o=Ht(Vt),n=B(e);return!e&&o?At(tn,{children:t}):At(en,{client:n,children:t})}function f(...e){return nn(on(e))}function rn(...e){let t=new Headers;for(let o of e)o&&new Headers(o).forEach((n,r)=>{t.set(r,n)});return t}function Se(e,t={},o){let n,r,i={};if(t&&typeof t=="object"){let u=t;"init"in u&&u.init&&typeof u.init=="object"&&(n=u.init),"auth"in u&&u.auth&&typeof u.auth=="object"&&(r=u.auth);let m=new Set(["init","auth","baseUrl","basePath","fetchUrl","client","user","tenants","disableQuery","onError","onSuccess","beforeMutate","onTenantChange","activeTenant","useCookie","className","emptyText","buttonText","profilePicturePlaceholder"]);for(let[d,g]of Object.entries(u))!m.has(d)&&g!==void 0&&(i[d]=g)}let a={...o?.auth?.requestInit??{},...o?.init??{},...r?.requestInit??{},...n??{},...i,headers:rn({"content-type":"application/json; charset=UTF-8"},o?.auth?.requestInit?.headers,o?.init?.headers,r?.requestInit?.headers,n?.headers,i.headers)},s=e;if(!(!!o?.fetchUrl||!!(t&&typeof t=="object"&&"fetchUrl"in t&&t.fetchUrl))&&e.startsWith("/")){let u=r??o?.auth,m=sn(o,t,u);s=`${an(o,t,u)}${m}${e}`}return fetch(s,a)}var an=(e,t={},o)=>e?.baseUrl?e.baseUrl:"baseUrl"in t&&t.baseUrl?t.baseUrl:o?.state?.baseUrl?o.state.baseUrl:He.state.baseUrl?He.state.baseUrl:"",sn=(e,t={},o)=>e?.basePath?e.basePath:"basePath"in t&&t.basePath?t.basePath:o?.state?.basePath?o.state.basePath:He.state.basePath?He.state.basePath:"";function qt(e){let{baseUrl:t="",basePath:o="/api",disableQuery:n,init:r,client:i,providersUrl:a,csrfUrl:s}=e??{},l=B(i);Qt({queryKey:["providers",t,o,a],queryFn:async()=>{let u=await fetch(a??`${t}${o}/auth/providers`,r);if(!u.ok)throw new Error(`Failed to fetch providers (${u.status})`);return await u.json()},enabled:n!==!0},l),Ve({baseUrl:t,basePath:o,disableQuery:n,init:r,client:i,csrfUrl:s})}function Ve(e){let{baseUrl:t="",basePath:o="/api",disableQuery:n,init:r,client:i,csrfUrl:a}=e??{},s=B(i);Qt({queryKey:["csrf",t,o,a],queryFn:async()=>{let l=await fetch(a??`${t}${o}/auth/csrf`,r);if(!l.ok)throw new Error(`Failed to fetch CSRF token (${l.status})`);return await l.json()},enabled:n!==!0},s)}import*as Wt from"react";import*as it from"@radix-ui/react-label";import{cva as ln}from"class-variance-authority";import{jsx as cn}from"react/jsx-runtime";var un=ln("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),at=Wt.forwardRef(({className:e,...t},o)=>cn(it.Root,{ref:o,className:f(un(),e),...t}));at.displayName=it.Root.displayName;import*as $t from"react";import{jsx as mn}from"react/jsx-runtime";var Q=$t.forwardRef(({className:e,type:t,...o},n)=>mn("input",{type:t,className:f("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...o}));Q.displayName="Input";import{jsx as F,jsxs as _t}from"react/jsx-runtime";var q=pn,Kt=H.createContext({}),me=({...e})=>F(Kt.Provider,{value:{name:e.name},children:F(fn,{...e})}),Qe=()=>{let e=H.useContext(Kt),t=H.useContext(Gt),{getFieldState:o,formState:n}=st(),r=o(e.name,n);if(!e)throw new Error("useFormField should be used within <FormField>");let{id:i}=t;return{id:i,name:e.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...r}},Gt=H.createContext({}),ne=H.forwardRef(({className:e,...t},o)=>{let n=H.useId();return F(Gt.Provider,{value:{id:n},children:F("div",{ref:o,className:f("py-2",e),...t})})});ne.displayName="FormItem";var re=H.forwardRef(({className:e,...t},o)=>{let{error:n,formItemId:r}=Qe();return F(at,{ref:o,className:f(n&&"text-destructive",e),htmlFor:r,...t})});re.displayName="FormLabel";var ie=H.forwardRef(({...e},t)=>{let{error:o,formItemId:n,formDescriptionId:r,formMessageId:i}=Qe();return F(dn,{ref:t,id:n,"aria-describedby":o?`${r} ${i}`:`${r}`,"aria-invalid":!!o,...e})});ie.displayName="FormControl";var de=H.forwardRef(({className:e,...t},o)=>{let{formDescriptionId:n}=Qe();return F("p",{ref:o,id:n,className:f("text-sm text-muted-foreground",e),...t})});de.displayName="FormDescription";var fe=H.forwardRef(({className:e,children:t,...o},n)=>{let{error:r,formMessageId:i}=Qe(),a=r?String(r?.message):t;return a?F("p",{ref:n,id:i,className:f("text-sm font-medium text-destructive",e),...o,children:a}):null});fe.displayName="FormMessage";var J=({hide:e})=>{let t=st();return F(me,{control:t.control,name:"email",render:({field:o})=>e?F("input",{type:"hidden",...o}):_t(ne,{children:[F(re,{children:"Email"}),F(ie,{children:F(Q,{placeholder:"Email",...o,type:"email","aria-label":o.name,autoComplete:"email",required:!0})}),F(de,{children:"Your email address"}),F(fe,{})]})})},pe=({autoComplete:e="current-password"}={})=>{let t=st();return F(me,{control:t.control,name:"password",render:({field:o})=>_t(ne,{children:[F(re,{children:"Password"}),F(ie,{children:F(Q,{placeholder:"Password",...o,type:"password","aria-label":o.name,autoComplete:e,required:!0})}),F(de,{children:"The desired password"}),F(fe,{})]})})};import*as Xt from"react";import{Slottable as gn,Slot as hn}from"@radix-ui/react-slot";import{cva as yn}from"class-variance-authority";import{Loader2 as bn}from"lucide-react";import{jsx as Me,jsxs as vn}from"react/jsx-runtime";var ae=yn("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 gap-1",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),R=Xt.forwardRef(({asChild:e=!1,children:t,className:o,disabled:n,loading:r,size:i,variant:a,...s},l)=>Me(e?hn:"button",{className:f(ae({variant:a,size:i,className:o})),ref:l,disabled:r||n,...s,children:Me(gn,{children:r?vn("div",{className:"relative flex items-center justify-center",children:[Me("div",{className:"absolute",children:Me(bn,{className:"animate-spin"})}),Me("span",{className:"opacity-0",children:t})]}):t})}));R.displayName="Button";import{useMutation as wn}from"@tanstack/react-query";import{signIn as Sn}from"@niledatabase/client";function lt(e){let{onSuccess:t,onError:o,beforeMutate:n,callbackUrl:r,redirect:i=!1,init:a,client:s}=e??{},l=B(s);return wn({mutationFn:async u=>{let m={...u,callbackUrl:r,redirect:i},g=(n&&n(m))??m,c=await Sn("email",{init:a,...g});if(i===!1&&!c||c&&(!c.ok||c.error))throw new Error(c?.error??"Email sign in failed");return c},onSuccess:t,onError:o},l)}function Yt(e){return lt(e).mutate}import{jsx as Pe,jsxs as Zt}from"react/jsx-runtime";function ut(e){let{client:t}=e??{};return Pe(U,{client:t,children:Pe(xn,{...e})})}function xn(e){let t=lt(e),o=Pn({defaultValues:{email:""}});return Pe(q,{...o,children:Zt("form",{onSubmit:o.handleSubmit(({email:n})=>t.mutate({email:n})),className:"space-y-8",children:[Pe(J,{}),!e.onError&&t.error?Pe("p",{role:"alert",className:"text-sm font-medium text-destructive",children:t.error instanceof Error?t.error.message:"Email sign in failed"}):null,Zt(R,{type:"submit",className:"flex flex-row gap-2",loading:t.isPending,children:[Pe(Cn,{"aria-hidden":"true"}),e.buttonText??"Sign in with email"]})]})})}import{Slot as Rn}from"@radix-ui/react-slot";import{Mail as Mn}from"lucide-react";import{signIn as Nn}from"@niledatabase/client";import{jsx as Jt,jsxs as Fn}from"react/jsx-runtime";var jt=({callbackUrl:e,className:t,variant:o,size:n,asChild:r=!1,redirect:i=!1,buttonText:a="Continue with Email",email:s,onFailure:l,onSent:u,fetchUrl:m,baseUrl:d,auth:g,init:c,loading:p,type:y="button",onClick:S,children:C,...b})=>Jt(r?Rn:"button",{...b,...r?{}:{type:y},className:f(ae({variant:o,size:n,className:t})),"data-slot":"email-signin-button",onClick:async v=>{let P=await Nn("email",{email:s,callbackUrl:e,redirect:i,fetchUrl:m,baseUrl:d,auth:g,init:c});S?.(v,P),i===!1&&!P||P&&(!P.ok||P.error)?l?.(P):u?.()},children:C||Fn("div",{className:"flex flex-row gap-2 items-center",children:[Jt(Mn,{"aria-hidden":"true"}),a]})});jt.displayName="EmailSignInButton";var eo=jt;import Dn from"react";import{Slot as En,Slottable as In}from"@radix-ui/react-slot";import{Loader2 as kn}from"lucide-react";import{signIn as Bn}from"@niledatabase/client";import{Fragment as Ln,jsx as Ne,jsxs as ct}from"react/jsx-runtime";function L({provider:e,dataSlot:t,defaultButtonText:o,providerClassName:n,icon:r,renderDefaultContent:i,callbackUrl:a,className:s,buttonText:l=o,variant:u,size:m,init:d,auth:g,fetchUrl:c,baseUrl:p,onClick:y,asChild:S=!1,loading:C=!1,disabled:b,type:E="button",children:v,...P}){let I=S&&Dn.isValidElement(v),N=async T=>{if(C||b){T.preventDefault();return}let Z=await Bn(e,{callbackUrl:a,init:d,auth:g,fetchUrl:c,baseUrl:p});y?.(T,Z)},Y=i?i(l,r):ct(Ln,{children:[r,l]}),ce=()=>{let T=v??Y;return C?ct("span",{className:"relative inline-flex items-center justify-center",children:[Ne("span",{className:"absolute",children:Ne(kn,{className:"animate-spin","aria-hidden":"true"})}),Ne("span",{className:"opacity-0 inline-flex items-center gap-4",children:T})]}):T};return I?ct(En,{...P,"aria-disabled":C||b||void 0,"data-slot":t,className:f(ae({variant:u,size:m,className:s}),n),onClick:N,children:[r,Ne(In,{children:v})]}):Ne("button",{...P,type:E,disabled:C||b,"data-slot":t,className:f(ae({variant:u,size:m,className:s}),n),onClick:N,children:ce()})}import{jsx as j,jsxs as no}from"react/jsx-runtime";var to=e=>j(L,{provider:"google",dataSlot:"google-button",defaultButtonText:"Continue with Google",providerClassName:"bg-[#4285f4] hover:bg-[#4285f4] hover:bg-opacity-85 pl-[3px] text-white",icon:j(Tn,{}),renderDefaultContent:(t,o)=>no("div",{className:"inline-flex items-center flex-1 justify-between font-roboto rounded-[4px] gap-4 google-logo",children:[j("div",{style:{background:"white",borderRadius:"4px",padding:"0.5rem"},children:o}),t]}),...e});to.displayName="GoogleSSOButton";var oo=to;function Tn(){return j("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",children:no("g",{fill:"#000",fillRule:"evenodd",children:[j("path",{d:"M9 3.48c1.69 0 2.83.73 3.48 1.34l2.54-2.48C13.46.89 11.43 0 9 0 5.48 0 2.44 2.02.96 4.96l2.91 2.26C4.6 5.05 6.62 3.48 9 3.48z",fill:"#EA4335"}),j("path",{d:"M17.64 9.2c0-.74-.06-1.28-.19-1.84H9v3.34h4.96c-.1.83-.64 2.08-1.84 2.92l2.84 2.2c1.7-1.57 2.68-3.88 2.68-6.62z",fill:"#4285F4"}),j("path",{d:"M3.88 10.78A5.54 5.54 0 0 1 3.58 9c0-.62.11-1.22.29-1.78L.96 4.96A9.008 9.008 0 0 0 0 9c0 1.45.35 2.82.96 4.04l2.92-2.26z",fill:"#FBBC05"}),j("path",{d:"M9 18c2.43 0 4.47-.8 5.96-2.18l-2.84-2.2c-.76.53-1.78.9-3.12.9-2.38 0-4.4-1.57-5.12-3.74L.97 13.04C2.45 15.98 5.48 18 9 18z",fill:"#34A853"}),j("path",{fill:"none",d:"M0 0h18v18H0z"})]})})}import{jsx as ge,jsxs as On}from"react/jsx-runtime";var ro=e=>ge(L,{provider:"azure-ad",dataSlot:"azure-button",defaultButtonText:"Continue with Microsoft",providerClassName:"bg-[#0078d4] hover:bg-[#0078d4] hover:bg-opacity-85 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:ge(zn,{}),...e});ro.displayName="AzureSignInButton";var Un=ro,zn=()=>On("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 23 23",className:"w-5 h-5 ml-3",children:[ge("path",{fill:"#f3f3f3",d:"M0 0h23v23H0z"}),ge("path",{fill:"#f35325",d:"M1 1h10v10H1z"}),ge("path",{fill:"#81bc06",d:"M12 1h10v10H12z"}),ge("path",{fill:"#05a6f0",d:"M1 12h10v10H1z"}),ge("path",{fill:"#ffba08",d:"M12 12h10v10H12z"})]});import{jsx as Ce}from"react/jsx-runtime";var io=e=>Ce(L,{provider:"discord",dataSlot:"discord-button",defaultButtonText:"Continue with Discord",providerClassName:"bg-[#5865F2] hover:bg-[#5865F2] hover:bg-opacity-85 pl-[3px] gap-4 transition-colors border shadow-md text-white",icon:Ce(Hn,{}),...e});io.displayName="DiscordSignInButton";var An=io,Hn=()=>Ce("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"0 0 75 59",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:Ce("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:Ce("g",{id:"discord-icon",transform:"translate(2.000000, 2.411745)",fillRule:"nonzero",stroke:"#636262",strokeWidth:"0",children:Ce("path",{d:"M60.1044999,4.48605546 C55.5791999,2.40965546 50.7264999,0.879855461 45.6526999,0.00367546142 C45.5602999,-0.0132345386 45.4679999,0.0290244614 45.4203999,0.113544461 C44.7962999,1.22355546 44.1049999,2.67165546 43.6208999,3.80985546 C38.1636999,2.99285546 32.7344999,2.99285546 27.3891999,3.80985546 C26.9049999,2.64635546 26.1885999,1.22355546 25.5616999,0.113544461 C25.5140999,0.0318444614 25.4217999,-0.0104145386 25.3293999,0.00367546142 C20.2583999,0.877055461 15.4056999,2.40685546 10.8775999,4.48605546 C10.8383999,4.50295546 10.8047999,4.53115546 10.7824999,4.56775546 C1.57794989,18.3191555 -0.94356111,31.7325555 0.29340789,44.9796555 C0.29900489,45.0444555 0.33538589,45.1064555 0.38576089,45.1458555 C6.45865989,49.6056555 12.3412999,52.3131555 18.1146999,54.1077555 C18.2070999,54.1359555 18.3049999,54.1021555 18.3637999,54.0260555 C19.7294999,52.1610555 20.9468999,50.1945555 21.9906999,48.1265555 C22.0522999,48.0054555 21.9934999,47.8617555 21.8675999,47.8138555 C19.9365999,47.0813555 18.0978999,46.1882555 16.3291999,45.1740555 C16.1892999,45.0923555 16.1780999,44.8922555 16.3067999,44.7964555 C16.6789999,44.5175555 17.0512999,44.2273555 17.4066999,43.9343555 C17.4709999,43.8808555 17.5605999,43.8695555 17.6361999,43.9033555 C29.2557999,49.2084555 41.8353999,49.2084555 53.3178999,43.9033555 C53.3934999,43.8667555 53.4830999,43.8780555 53.5501999,43.9315555 C53.9056999,44.2245555 54.2778999,44.5175555 54.6528999,44.7964555 C54.7815999,44.8922555 54.7731999,45.0923555 54.6332999,45.1740555 C52.8645999,46.2079555 51.0258999,47.0813555 49.0920999,47.8110555 C48.9661999,47.8589555 48.9101999,48.0054555 48.9717999,48.1265555 C50.0379999,50.1916555 51.2553999,52.1581555 52.5958999,54.0232555 C52.6518999,54.1021555 52.7525999,54.1359555 52.8449999,54.1077555 C58.6463999,52.3131555 64.5289999,49.6056555 70.6018999,45.1458555 C70.6550999,45.1064555 70.6886999,45.0472555 70.6942999,44.9824555 C72.1746999,29.6673555 68.2146999,16.3639555 60.1967999,4.57055546 C60.1771999,4.53115546 60.1436999,4.50295546 60.1044999,4.48605546 Z M23.7258999,36.9135555 C20.2275999,36.9135555 17.3450999,33.7018555 17.3450999,29.7575555 C17.3450999,25.8132555 20.1716999,22.6015555 23.7258999,22.6015555 C27.3079999,22.6015555 30.1625999,25.8414555 30.1065999,29.7575555 C30.1065999,33.7018555 27.2799999,36.9135555 23.7258999,36.9135555 Z M47.3177999,36.9135555 C43.8195999,36.9135555 40.9370999,33.7018555 40.9370999,29.7575555 C40.9370999,25.8132555 43.7635999,22.6015555 47.3177999,22.6015555 C50.8999999,22.6015555 53.7544999,25.8414555 53.6985999,29.7575555 C53.6985999,33.7018555 50.8999999,36.9135555 47.3177999,36.9135555 Z",id:"Shape",fill:"white"})})})});import{jsx as qe}from"react/jsx-runtime";var ao=e=>qe(L,{provider:"github",dataSlot:"github-button",defaultButtonText:"Continue with GitHub",providerClassName:"bg-black hover:bg-slate-800 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:qe(Qn,{}),...e});ao.displayName="GitHubSignInButton";var Vn=ao,Qn=()=>qe("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32.58 31.77",fill:"currentColor",className:"w-5 h-5 ml-3",children:qe("path",{fill:"#FFFFFF",d:"M16.29,0a16.29,16.29,0,0,0-5.15,31.75c.82.15,1.11-.36,1.11-.79s0-1.41,0-2.77C7.7,29.18,6.74,26,6.74,26a4.36,4.36,0,0,0-1.81-2.39c-1.47-1,.12-1,.12-1a3.43,3.43,0,0,1,2.49,1.68,3.48,3.48,0,0,0,4.74,1.36,3.46,3.46,0,0,1,1-2.18c-3.62-.41-7.42-1.81-7.42-8a6.3,6.3,0,0,1,1.67-4.37,5.94,5.94,0,0,1,.16-4.31s1.37-.44,4.48,1.67a15.41,15.41,0,0,1,8.16,0c3.11-2.11,4.47-1.67,4.47-1.67A5.91,5.91,0,0,1,25,11.07a6.3,6.3,0,0,1,1.67,4.37c0,6.26-3.81,7.63-7.44,8a3.85,3.85,0,0,1,1.11,3c0,2.18,0,3.94,0,4.47s.29.94,1.12.78A16.29,16.29,0,0,0,16.29,0Z"})});import{jsx as We}from"react/jsx-runtime";var so=e=>We(L,{provider:"hubspot",dataSlot:"hubspot-button",defaultButtonText:"Continue with HubSpot",providerClassName:"bg-[#ff7a59] hover:bg-[#ff7a59] hover:bg-opacity-85 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:We(Wn,{}),...e});so.displayName="HubSpotSignInButton";var qn=so,Wn=()=>We("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"6.20856283 .64498824 244.26943717 251.24701176",xmlns:"http://www.w3.org/2000/svg",children:We("path",{d:"m191.385 85.694v-29.506a22.722 22.722 0 0 0 13.101-20.48v-.677c0-12.549-10.173-22.722-22.721-22.722h-.678c-12.549 0-22.722 10.173-22.722 22.722v.677a22.722 22.722 0 0 0 13.101 20.48v29.506a64.342 64.342 0 0 0 -30.594 13.47l-80.922-63.03c.577-2.083.878-4.225.912-6.375a25.6 25.6 0 1 0 -25.633 25.55 25.323 25.323 0 0 0 12.607-3.43l79.685 62.007c-14.65 22.131-14.258 50.974.987 72.7l-24.236 24.243c-1.96-.626-4-.959-6.057-.987-11.607.01-21.01 9.423-21.007 21.03.003 11.606 9.412 21.014 21.018 21.017 11.607.003 21.02-9.4 21.03-21.007a20.747 20.747 0 0 0 -.988-6.056l23.976-23.985c21.423 16.492 50.846 17.913 73.759 3.562 22.912-14.352 34.475-41.446 28.985-67.918-5.49-26.473-26.873-46.734-53.603-50.792m-9.938 97.044a33.17 33.17 0 1 1 0-66.316c17.85.625 32 15.272 32.01 33.134.008 17.86-14.127 32.522-31.977 33.165",fill:"white"})});import{jsx as $e,jsxs as Gn}from"react/jsx-runtime";var lo=e=>$e(L,{provider:"linkedin",dataSlot:"linkedin-button",defaultButtonText:"Continue with LinkedIn",providerClassName:"bg-[#0288D1] hover:bg-[#0288D1] pl-[3px] hover:bg-opacity-85 gap-4 transition-colors shadow-md text-white",icon:$e(Kn,{}),...e});lo.displayName="LinkedInSignInButton";var $n=lo,Kn=()=>Gn("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 48 48",className:"w-6 h-6 ml-3",children:[$e("path",{fill:"#fff",d:"M42,37c0,2.762-2.238,5-5,5H11c-2.761,0-5-2.238-5-5V11c0-2.762,2.239-5,5-5h26c2.762,0,5,2.238,5,5V37z"}),$e("path",{fill:"#0288D1",d:"M12 19H17V36H12zM14.485 17h-.028C12.965 17 12 15.888 12 14.499 12 13.08 12.995 12 14.514 12c1.521 0 2.458 1.08 2.486 2.499C17 15.887 16.035 17 14.485 17zM36 36h-5v-9.099c0-2.198-1.225-3.698-3.192-3.698-1.501 0-2.313 1.012-2.707 1.99C24.957 25.543 25 26.511 25 27v9h-5V19h5v2.616C25.721 20.5 26.85 19 29.738 19c3.578 0 6.261 2.25 6.261 7.274L36 36 36 36z"})]});import{jsx as he,jsxs as Yn}from"react/jsx-runtime";var uo=e=>he(L,{provider:"slack",dataSlot:"slack-button",defaultButtonText:"Continue with Slack",providerClassName:"bg-[#4A154B] pl-[3px] hover:bg-opacity-85 gap-4 transition-colors shadow-md text-white",icon:he(Xn,{}),...e});uo.displayName="SlackSignInButton";var _n=uo,Xn=()=>he("svg",{"aria-hidden":"true",focusable:"false",enableBackground:"new 0 0 2447.6 2452.5",viewBox:"0 0 2447.6 2452.5",className:"w-5 h-5 ml-3",xmlns:"http://www.w3.org/2000/svg",children:Yn("g",{clipRule:"evenodd",fillRule:"evenodd",children:[he("path",{d:"m897.4 0c-135.3.1-244.8 109.9-244.7 245.2-.1 135.3 109.5 245.1 244.8 245.2h244.8v-245.1c.1-135.3-109.5-245.1-244.9-245.3.1 0 .1 0 0 0m0 654h-652.6c-135.3.1-244.9 109.9-244.8 245.2-.2 135.3 109.4 245.1 244.7 245.3h652.7c135.3-.1 244.9-109.9 244.8-245.2.1-135.4-109.5-245.2-244.8-245.3z",fill:"#36c5f0"}),he("path",{d:"m2447.6 899.2c.1-135.3-109.5-245.1-244.8-245.2-135.3.1-244.9 109.9-244.8 245.2v245.3h244.8c135.3-.1 244.9-109.9 244.8-245.3zm-652.7 0v-654c.1-135.2-109.4-245-244.7-245.2-135.3.1-244.9 109.9-244.8 245.2v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.3z",fill:"#2eb67d"}),he("path",{d:"m1550.1 2452.5c135.3-.1 244.9-109.9 244.8-245.2.1-135.3-109.5-245.1-244.8-245.2h-244.8v245.2c-.1 135.2 109.5 245 244.8 245.2zm0-654.1h652.7c135.3-.1 244.9-109.9 244.8-245.2.2-135.3-109.4-245.1-244.7-245.3h-652.7c-135.3.1-244.9 109.9-244.8 245.2-.1 135.4 109.4 245.2 244.7 245.3z",fill:"#ecb22e"}),he("path",{d:"m0 1553.2c-.1 135.3 109.5 245.1 244.8 245.2 135.3-.1 244.9-109.9 244.8-245.2v-245.2h-244.8c-135.3.1-244.9 109.9-244.8 245.2zm652.7 0v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.2v-653.9c.2-135.3-109.4-245.1-244.7-245.3-135.4 0-244.9 109.8-244.8 245.1 0 0 0 .1 0 0",fill:"#e01e5a"})]})});import{jsx as Ke}from"react/jsx-runtime";var co=e=>Ke(L,{provider:"twitter",dataSlot:"twitter-button",defaultButtonText:"Continue with X",providerClassName:"bg-black hover:bg-slate-800 pl-[3px] text-white gap-4 transition-colors shadow-md",icon:Ke(Jn,{}),...e});co.displayName="XSignInButton";var Zn=co,Jn=()=>Ke("svg",{"aria-hidden":"true",focusable:"false",className:"w-5 h-5 ml-3",viewBox:"0 0 24 24",version:"1.1",children:Ke("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",fill:"#ffffff"})});import{jsx as Fe}from"react/jsx-runtime";var mo=e=>Fe(L,{provider:"okta",dataSlot:"okta-button",defaultButtonText:"Continue with Okta",providerClassName:"bg-[#181818] hover:bg-[#3f59e4] pl-[3px] gap-4 transition-colors shadow-md text-white",icon:Fe(er,{}),...e});mo.displayName="OktaSignInButton";var jn=mo,er=()=>Fe("svg",{"aria-hidden":"true",focusable:"false",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 63 63",fill:"currentColor",className:"w-5 h-5 ml-3",width:"18",height:"18",children:Fe("g",{children:Fe("path",{d:`M34.6,0.4l-1.3,16c-0.6-0.1-1.2-0.1-1.9-0.1c-0.8,0-1.6,0.1-2.3,0.2l-0.7-7.7c0-0.2,0.2-0.5,0.4-0.5h1.3
|
|
3
3
|
l-0.6-7.8c0-0.2,0.2-0.5,0.4-0.5h4.3C34.5,0,34.7,0.2,34.6,0.4L34.6,0.4L34.6,0.4z M23.8,1.2c-0.1-0.2-0.3-0.4-0.5-0.3l-4,1.5
|
|
4
4
|
C19,2.5,18.9,2.8,19,3l3.3,7.1l-1.2,0.5c-0.2,0.1-0.3,0.3-0.2,0.6l3.3,7c1.2-0.7,2.5-1.2,3.9-1.5L23.8,1.2L23.8,1.2z M14,5.7
|
|
5
5
|
l9.3,13.1c-1.2,0.8-2.2,1.7-3.1,2.7L14.5,16c-0.2-0.2-0.2-0.5,0-0.6l1-0.8L10,9c-0.2-0.2-0.2-0.5,0-0.6l3.3-2.7
|
|
@@ -24,8 +24,8 @@ import se from"react";import{useForm as Zo}from"react-hook-form";import{Mail as
|
|
|
24
24
|
L52.2,42l7.1,3.4c0.2,0.1,0.3,0.4,0.2,0.6L57.4,49.6C57.4,49.6,57.4,49.6,57.4,49.6z M39.7,44.2L49,57.3c0.1,0.2,0.4,0.2,0.6,0.1
|
|
25
25
|
l3.3-2.7c0.2-0.2,0.2-0.4,0-0.6l-5.5-5.6l1-0.8c0.2-0.2,0.2-0.4,0-0.6l-5.5-5.5C42,42.6,40.9,43.5,39.7,44.2L39.7,44.2L39.7,44.2z
|
|
26
26
|
M39.7,62c-0.2,0.1-0.5-0.1-0.5-0.3l-4.2-15.4c1.4-0.3,2.7-0.8,3.9-1.5l3.3,7c0.1,0.2,0,0.5-0.2,0.6l-1.2,0.5l3.3,7.1
|
|
27
|
-
c0.1,0.2,0,0.5-0.2,0.6L39.7,62L39.7,62L39.7,62z`})));import st from"react";import ue,{useState as to}from"react";import{useForm as Dr}from"react-hook-form";import{useMutation as Mr}from"@tanstack/react-query";import{signUp as Nr}from"@niledatabase/client";function Fr(e={},t){let{onSuccess:o,onError:r,beforeMutate:n,client:i,...s}=e??{},a=z(t??i),l=Mr({mutationFn:async u=>{let c=n&&n(u),d={...u,...c},g=await Nr({...s,...d});if(!g)return;let{data:m,error:p}=g;if(p)throw new Error(p);return m},onSuccess:o,onError:r},a);return At(e),l}function Qe(e={},t){return Fr(e,t).mutate}function it(e){let{client:t}=e??{};return ue.createElement(Q,{client:t},ue.createElement(Er,{...e}))}function Er(e){let[t,o]=to(!1),[r,n]=to(null),i=Qe({...e,onSuccess:(a,l)=>{o(!1),n(null),e.onSuccess?.(a,l)},onError:(a,l)=>{o(!1),n(a instanceof Error?a.message:"Sign up failed"),e.onError?.(a,l)}}),s=Dr({defaultValues:{email:"",password:""}});return ue.createElement(W,{...s},ue.createElement("form",{onSubmit:s.handleSubmit(({email:a,password:l})=>{o(!0),n(null),i?.({email:a,password:l})}),className:"space-y-8"},ue.createElement(Z,null),ue.createElement(be,{autoComplete:"new-password"}),!e.onError&&r?ue.createElement("p",{role:"alert",className:"text-sm font-medium text-destructive"},r):null,ue.createElement(E,{type:"submit",loading:t},e.buttonText??"Sign up")))}function at({className:e,...t}){return st.createElement("div",{className:f(e,"flex flex-col gap-4")},st.createElement("h2",{className:"font-sans text-3xl"},"Sign up"),st.createElement(it,{...t}))}import ut from"react";import me,{useState as oo}from"react";import{useForm as Lr}from"react-hook-form";import{useMutation as Ir}from"@tanstack/react-query";import{signIn as kr}from"@niledatabase/client";function Br(e){let{onSuccess:t,onError:o,beforeMutate:r,callbackUrl:n,init:i,baseUrl:s,fetchUrl:a,resetUrl:l,auth:u,redirect:c,client:d}=e??{},g=z(d);return Ir({mutationFn:async m=>{let p={...m,callbackUrl:n},M=(r&&r(p))??p,F=await kr(M.provider,{init:i,auth:u,baseUrl:s,fetchUrl:a,redirect:c,resetUrl:l,...M});if(c===!1&&!F)throw new Error("Sign in failed");if(F&&(!F.ok||F.error))throw new Error(F.error??"Sign in failed");return F},onSuccess:t,onError:o},g)}function qe(e){return Br(e).mutate}function lt(e){let{client:t}=e??{};return me.createElement(Q,{client:t},me.createElement(Tr,{...e}))}function Tr(e){let[t,o]=oo(!1),[r,n]=oo(null),i=qe({...e,onSuccess:(...a)=>{o(!1),n(null),e.onSuccess?.(...a)},onError:(a,l)=>{o(!1),n(a instanceof Error?a.message:"Sign in failed"),e.onError?.(a,l)}}),s=Lr({defaultValues:{email:"",password:""}});return me.createElement(W,{...s},me.createElement("form",{onSubmit:s.handleSubmit(({email:a,password:l})=>{o(!0),n(null),i?.({provider:"credentials",email:a,password:l})}),className:"space-y-8"},me.createElement(Z,null),me.createElement(be,{autoComplete:"current-password"}),!e.onError&&r?me.createElement("p",{role:"alert",className:"text-sm font-medium text-destructive"},r):null,me.createElement(E,{type:"submit",loading:t},e.buttonText??"Sign In")))}function mt({className:e,...t}){return ut.createElement("div",{className:f(e,"flex flex-col gap-4")},ut.createElement("h2",{className:"font-sans text-3xl"},"Sign In"),ut.createElement(lt,{...t}))}import ct from"react";import{Slot as Ur}from"@radix-ui/react-slot";import{LogOut as zr}from"lucide-react";import{signOut as Or}from"@niledatabase/client";var ro=({callbackUrl:e,redirect:t,className:o,buttonText:r="Sign out",variant:n,size:i,baseUrl:s,fetchUrl:a,basePath:l,auth:u,init:c,loading:d,type:g="button",asChild:m=!1,onClick:p,children:v,...M})=>ct.createElement(m?Ur:"button",{...M,...m?{}:{type:g},"data-slot":"signout-button",className:ie({variant:n,size:i,className:o}),onClick:x=>{Or({callbackUrl:e,redirect:t,baseUrl:s,auth:u,fetchUrl:a,basePath:l,init:c}),p?.(x)}},v||ct.createElement("div",{className:"flex flex-row gap-2 items-center"},ct.createElement(zr,{"aria-hidden":"true"}),r));ro.displayName="SignOutButton";var Rr=ro;import ft,{useMemo as Kr}from"react";import $ from"react";import{auth as k,getStatus as Ar,broadcast as Hr}from"@niledatabase/client";function Vr(){let[e,t]=$.useState(!0);return $.useEffect(()=>{typeof navigator<"u"&&typeof navigator.onLine=="boolean"&&t(navigator.onLine);let o=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",o),window.addEventListener("offline",r),()=>{window.removeEventListener("online",o),window.removeEventListener("offline",r)}},[]),e}var dt=()=>({basePath:k.state.basePath,baseUrl:k.state.baseUrl,lastSync:k.state.lastSync,getSession:k.state.getSession,session:k.state.session,loading:k.state.loading}),Qr=Object.freeze({basePath:k.state.basePath,baseUrl:k.state.baseUrl,lastSync:0,getSession:()=>{},session:void 0,loading:!0}),ee=dt(),qr=e=>{let t=()=>{ee=dt(),e()};return k.addListener(t),()=>k.removeListener(t)},jr=()=>{let e=k.state;return(ee.session!==e.session||ee.loading!==e.loading||ee.basePath!==e.basePath||ee.baseUrl!==e.baseUrl||ee.lastSync!==e.lastSync||ee.getSession!==e.getSession)&&(ee=dt()),ee},Wr=()=>Qr;function $r(){return $.useSyncExternalStore(qr,jr,Wr)}var Me=$.createContext?.(void 0);function Ne(e){if(!Me)throw new Error("React Context is unavailable in Server Components");let t=$.useContext(Me);if(!t)throw new Error("useSession must be wrapped in a <SessionProvider />");let{required:o,onUnauthenticated:r}=e??{},n=o&&t.status==="unauthenticated",i=t.state?.basePath||k.state.basePath||"/api";return $.useEffect(()=>{if(n&&typeof window<"u"){let s=`${i}/auth/signin?${new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href})}`;r?r():window.location.href=s}},[n,r,i]),n?{data:t.data,update:t.update,status:"loading",state:t.state}:t}function no(e){return typeof Response<"u"&&e instanceof Response}function Fe(e){if(!Me)throw new Error("React Context is unavailable in Server Components");let{children:t,refetchWhenOffline:o,refetchInterval:r,refetchOnWindowFocus:n=!0}=e,i=$r(),s=e.session!==void 0&&!no(e.session)?e.session:void 0,a=i.session===void 0?s??null:i.session??null;$.useEffect(()=>{(e.basePath||e.baseUrl)&&k.configure({basePath:e.basePath,baseUrl:e.baseUrl}),e.session!==void 0&&!no(e.session)?k.initialize({baseUrl:e.baseUrl,session:e.session}):k.status||k.getSession({baseUrl:e.baseUrl})},[e.basePath,e.baseUrl,e.session]);let l=Vr(),u=o!==!1||l,c=$.useCallback(()=>{document.visibilityState==="visible"&&k.sync("visibilitychange")},[]);$.useEffect(()=>{if(r&&u){let p=setInterval(()=>{k.state.session&&k.getSession({event:"poll"})},r*1e3);return()=>clearInterval(p)}},[r,u]),$.useEffect(()=>{n?document.addEventListener("visibilitychange",c,!1):document.removeEventListener("visibilitychange",c);let p=Hr.receive(()=>k.sync("storage"));return()=>{p(),document.removeEventListener("visibilitychange",c,!1)}},[n,c]);let d=i.session===void 0&&s!==void 0?!1:i.loading,g=Ar(d,a),m=$.useMemo(()=>({data:a??null,status:g,state:i,async update(){return await k.refreshSession()}}),[a,i,g]);return $.createElement(Me.Provider,{value:m},t)}function pt(e){return e&&"exp"in e?{...e,expires:new Date(e.exp*1e3).toISOString()}:e}function io({children:e,session:t,...o}){let r=typeof Response<"u"&&t instanceof Response,n=Kr(()=>r?null:pt(t),[r,t]);return r?null:ft.createElement(Fe,{...o,session:n},ft.createElement(Gr,{className:o.className},e))}function Gr({children:e,className:t}){let{status:o}=Ne();return o==="authenticated"?t?ft.createElement("div",{className:t},e):e:null}import gt,{useMemo as _r}from"react";function so({children:e,session:t,...o}){let r=_r(()=>typeof Response<"u"&&t instanceof Response?t.ok?void 0:null:pt(t),[t]);return gt.createElement(Fe,{...o,session:r},gt.createElement(Xr,{className:o.className},e))}function Xr({className:e,children:t}){let{status:o}=Ne();return o==="unauthenticated"?e?gt.createElement("div",{className:e},t):t:null}import{mfa as mo,sanitizeRedirectUrl as co}from"@niledatabase/client";import{useState as De,useEffect as Zr,useCallback as Ge}from"react";var je=e=>typeof e=="object"&&e!==null,ao=e=>e==="setup"||e==="challenge",Yr=e=>{if(!Array.isArray(e))return;let t=e.filter(o=>typeof o=="string"&&o.trim().length>0);return t.length>0?t:void 0},lo=e=>!je(e)||e.method!=="authenticator"||!ao(e.scope)||typeof e.token!="string"?null:{method:"authenticator",token:e.token,scope:e.scope,otpauthUrl:typeof e.otpauthUrl=="string"?e.otpauthUrl:void 0,secret:typeof e.secret=="string"?e.secret:void 0,recoveryKeys:Yr(e.recoveryKeys)},uo=e=>!je(e)||e.method!=="email"||!ao(e.scope)||typeof e.token!="string"?null:{method:"email",token:e.token,scope:e.scope,maskedEmail:typeof e.maskedEmail=="string"&&e.maskedEmail.trim().length>0?e.maskedEmail:void 0};var We="nile.mfa.challenge";function $e(e){if(!(typeof window>"u"))try{window.sessionStorage.setItem(We,JSON.stringify(e))}catch{}}function Ke(){if(typeof window>"u")return null;try{let e=window.sessionStorage.getItem(We);if(!e)return null;let t=JSON.parse(e);if(t&&typeof t=="object"&&typeof t.token=="string"&&(t.method==="email"||t.method==="authenticator")&&(t.scope==="setup"||t.scope==="challenge"))return{token:t.token,method:t.method,scope:t.scope,destination:typeof t.destination=="string"?t.destination:void 0}}catch{}return null}function Se(){if(!(typeof window>"u"))try{window.sessionStorage.removeItem(We)}catch{}}var fo="/mfa/prompt",go=({method:e,currentMethod:t,promptPath:o=fo,onRedirect:r,onChallengeRedirect:n})=>{let[i,s]=De(null),[a,l]=De(null),[u,c]=De(null),[d,g]=De(!1),[m,p]=De(!1),v=e==="authenticator"?lo:uo,M=Ge(S=>{let N=co(S);if(r){r(N);return}typeof window<"u"&&window.location.assign(N)},[r]),F=Ge(S=>{if(n){n(S);return}$e(S);let N=new URLSearchParams({method:S.method,scope:S.scope});S.destination&&N.set("destination",S.destination);let L=co(o,{fallback:fo}),I=L.includes("?")?"&":"?";M(`${L}${I}${N.toString()}`)},[M,n,o]),x=Ge(async()=>{g(!0),l(null),c(null);try{let S=await mo({scope:"setup",method:e}),N=po(S);if(N){s(null),l("setup"),c(N);return}let L=ht(S);if(L){M(L);return}let I=v(S);if(!I){s(null),l("parseSetup");return}if(I.scope==="challenge"){F({token:I.token,method:I.method,scope:I.scope,destination:"maskedEmail"in I?I.maskedEmail:void 0});return}s(I)}catch{l("setup"),s(null)}finally{g(!1)}},[e,M,v,F]),B=Ge(async()=>{p(!0),l(null),c(null);try{let S=await mo({method:e}),N=po(S);if(N){l("disable"),c(N);return}let L=ht(S);if(L){M(L);return}let I=v(S);if(!I){l("parseDisable");return}s(I)}catch{l("disable")}finally{p(!1)}},[e,M,v]);return Zr(()=>(l(null),c(null),s(null),()=>{s(null)}),[t]),{setup:i,loading:d||m,errorType:a,errorMessage:u,startSetup:x,startDisable:B}},ht=e=>je(e)&&typeof e.url=="string"||typeof Response<"u"&&e instanceof Response&&typeof e.url=="string"?e.url:null,po=e=>{let t=ht(e);if(!t)return null;try{let o=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",n=new URL(t,o).searchParams.get("error");if(n)return n}catch{return null}return null};import fe from"react";import vt from"react-qr-code";import q from"react";import{Copy as Jr,Download as en}from"lucide-react";import{useState as tn,useMemo as on,useEffect as rn}from"react";function yt({setup:e,onError:t}){let[o,r]=tn("idle"),n=on(()=>e.recoveryKeys?.join(`
|
|
28
|
-
`)??"",[e.recoveryKeys]);return
|
|
27
|
+
c0.1,0.2,0,0.5-0.2,0.6L39.7,62L39.7,62L39.7,62z`})})});import{useState as fo}from"react";import{useForm as rr}from"react-hook-form";import{useMutation as tr}from"@tanstack/react-query";import{signUp as or}from"@niledatabase/client";function nr(e={},t){let{onSuccess:o,onError:n,beforeMutate:r,client:i,...a}=e??{},s=B(t??i),l=tr({mutationFn:async u=>{let m=r&&r(u),d={...u,...m},g=await or({...a,...d});if(!g)return;let{data:c,error:p}=g;if(p)throw new Error(p);return c},onSuccess:o,onError:n},s);return qt(e),l}function Ge(e={},t){return nr(e,t).mutate}import{jsx as ye,jsxs as ar}from"react/jsx-runtime";function mt(e){let{client:t}=e??{};return ye(U,{client:t,children:ye(ir,{...e})})}function ir(e){let[t,o]=fo(!1),[n,r]=fo(null),i=Ge({...e,onSuccess:(s,l)=>{o(!1),r(null),e.onSuccess?.(s,l)},onError:(s,l)=>{o(!1),r(s instanceof Error?s.message:"Sign up failed"),e.onError?.(s,l)}}),a=rr({defaultValues:{email:"",password:""}});return ye(q,{...a,children:ar("form",{onSubmit:a.handleSubmit(({email:s,password:l})=>{o(!0),r(null),i?.({email:s,password:l})}),className:"space-y-8",children:[ye(J,{}),ye(pe,{autoComplete:"new-password"}),!e.onError&&n?ye("p",{role:"alert",className:"text-sm font-medium text-destructive",children:n}):null,ye(R,{type:"submit",loading:t,children:e.buttonText??"Sign up"})]})})}import{jsx as po,jsxs as sr}from"react/jsx-runtime";function dt({className:e,...t}){return sr("div",{className:f(e,"flex flex-col gap-4"),children:[po("h2",{className:"font-sans text-3xl",children:"Sign up"}),po(mt,{...t})]})}import{useState as go}from"react";import{useForm as mr}from"react-hook-form";import{useMutation as lr}from"@tanstack/react-query";import{signIn as ur}from"@niledatabase/client";function cr(e){let{onSuccess:t,onError:o,beforeMutate:n,callbackUrl:r,init:i,baseUrl:a,fetchUrl:s,resetUrl:l,auth:u,redirect:m,client:d}=e??{},g=B(d);return lr({mutationFn:async c=>{let p={...c,callbackUrl:r},S=(n&&n(p))??p,C=await ur(S.provider,{init:i,auth:u,baseUrl:a,fetchUrl:s,redirect:m,resetUrl:l,...S});if(m===!1&&!C)throw new Error("Sign in failed");if(C&&(!C.ok||C.error))throw new Error(C.error??"Sign in failed");return C},onSuccess:t,onError:o},g)}function _e(e){return cr(e).mutate}import{jsx as be,jsxs as fr}from"react/jsx-runtime";function ft(e){let{client:t}=e??{};return be(U,{client:t,children:be(dr,{...e})})}function dr(e){let[t,o]=go(!1),[n,r]=go(null),i=_e({...e,onSuccess:(...s)=>{o(!1),r(null),e.onSuccess?.(...s)},onError:(s,l)=>{o(!1),r(s instanceof Error?s.message:"Sign in failed"),e.onError?.(s,l)}}),a=mr({defaultValues:{email:"",password:""}});return be(q,{...a,children:fr("form",{onSubmit:a.handleSubmit(({email:s,password:l})=>{o(!0),r(null),i?.({provider:"credentials",email:s,password:l})}),className:"space-y-8",children:[be(J,{}),be(pe,{autoComplete:"current-password"}),!e.onError&&n?be("p",{role:"alert",className:"text-sm font-medium text-destructive",children:n}):null,be(R,{type:"submit",loading:t,children:e.buttonText??"Sign In"})]})})}import{jsx as ho,jsxs as pr}from"react/jsx-runtime";function pt({className:e,...t}){return pr("div",{className:f(e,"flex flex-col gap-4"),children:[ho("h2",{className:"font-sans text-3xl",children:"Sign In"}),ho(ft,{...t})]})}import{Slot as gr}from"@radix-ui/react-slot";import{LogOut as hr}from"lucide-react";import{signOut as yr}from"@niledatabase/client";import{jsx as yo,jsxs as vr}from"react/jsx-runtime";var bo=({callbackUrl:e,redirect:t,className:o,buttonText:n="Sign out",variant:r,size:i,baseUrl:a,fetchUrl:s,basePath:l,auth:u,init:m,loading:d,type:g="button",asChild:c=!1,onClick:p,children:y,...S})=>yo(c?gr:"button",{...S,...c?{}:{type:g},"data-slot":"signout-button",className:ae({variant:r,size:i,className:o}),onClick:b=>{yr({callbackUrl:e,redirect:t,baseUrl:a,auth:u,fetchUrl:s,basePath:l,init:m}),p?.(b)},children:y||vr("div",{className:"flex flex-row gap-2 items-center",children:[yo(hr,{"aria-hidden":"true"}),n]})});bo.displayName="SignOutButton";var br=bo;import{useMemo as Dr}from"react";import K from"react";import{auth as D,getStatus as wr,broadcast as Sr}from"@niledatabase/client";import{jsx as Fr}from"react/jsx-runtime";function Pr(){let[e,t]=K.useState(!0);return K.useEffect(()=>{typeof navigator<"u"&&typeof navigator.onLine=="boolean"&&t(navigator.onLine);let o=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",o),window.addEventListener("offline",n),()=>{window.removeEventListener("online",o),window.removeEventListener("offline",n)}},[]),e}var gt=()=>({basePath:D.state.basePath,baseUrl:D.state.baseUrl,lastSync:D.state.lastSync,getSession:D.state.getSession,session:D.state.session,loading:D.state.loading}),Cr=Object.freeze({basePath:D.state.basePath,baseUrl:D.state.baseUrl,lastSync:0,getSession:()=>{},session:void 0,loading:!0}),ee=gt(),xr=e=>{let t=()=>{ee=gt(),e()};return D.addListener(t),()=>D.removeListener(t)},Rr=()=>{let e=D.state;return(ee.session!==e.session||ee.loading!==e.loading||ee.basePath!==e.basePath||ee.baseUrl!==e.baseUrl||ee.lastSync!==e.lastSync||ee.getSession!==e.getSession)&&(ee=gt()),ee},Mr=()=>Cr;function Nr(){return K.useSyncExternalStore(xr,Rr,Mr)}var De=K.createContext?.(void 0);function Ee(e){if(!De)throw new Error("React Context is unavailable in Server Components");let t=K.useContext(De);if(!t)throw new Error("useSession must be wrapped in a <SessionProvider />");let{required:o,onUnauthenticated:n}=e??{},r=o&&t.status==="unauthenticated",i=t.state?.basePath||D.state.basePath||"/api";return K.useEffect(()=>{if(r&&typeof window<"u"){let a=`${i}/auth/signin?${new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href})}`;n?n():window.location.href=a}},[r,n,i]),r?{data:t.data,update:t.update,status:"loading",state:t.state}:t}function vo(e){return typeof Response<"u"&&e instanceof Response}function Ie(e){if(!De)throw new Error("React Context is unavailable in Server Components");let{children:t,refetchWhenOffline:o,refetchInterval:n,refetchOnWindowFocus:r=!0}=e,i=Nr(),a=e.session!==void 0&&!vo(e.session)?e.session:void 0,s=i.session===void 0?a??null:i.session??null;K.useEffect(()=>{(e.basePath||e.baseUrl)&&D.configure({basePath:e.basePath,baseUrl:e.baseUrl}),e.session!==void 0&&!vo(e.session)?D.initialize({baseUrl:e.baseUrl,session:e.session}):D.status||D.getSession({baseUrl:e.baseUrl})},[e.basePath,e.baseUrl,e.session]);let l=Pr(),u=o!==!1||l,m=K.useCallback(()=>{document.visibilityState==="visible"&&D.sync("visibilitychange")},[]);K.useEffect(()=>{if(n&&u){let p=setInterval(()=>{D.state.session&&D.getSession({event:"poll"})},n*1e3);return()=>clearInterval(p)}},[n,u]),K.useEffect(()=>{r?document.addEventListener("visibilitychange",m,!1):document.removeEventListener("visibilitychange",m);let p=Sr.receive(()=>D.sync("storage"));return()=>{p(),document.removeEventListener("visibilitychange",m,!1)}},[r,m]);let d=i.session===void 0&&a!==void 0?!1:i.loading,g=wr(d,s),c=K.useMemo(()=>({data:s??null,status:g,state:i,async update(){return await D.refreshSession()}}),[s,i,g]);return Fr(De.Provider,{value:c,children:t})}import{jsx as ht}from"react/jsx-runtime";function yt(e){return e&&"exp"in e?{...e,expires:new Date(e.exp*1e3).toISOString()}:e}function wo({children:e,session:t,...o}){let n=typeof Response<"u"&&t instanceof Response,r=Dr(()=>n?null:yt(t),[n,t]);return n?null:ht(Ie,{...o,session:r,children:ht(Er,{className:o.className,children:e})})}function Er({children:e,className:t}){let{status:o}=Ee();return o==="authenticated"?t?ht("div",{className:t,children:e}):e:null}import{useMemo as Ir}from"react";import{jsx as bt}from"react/jsx-runtime";function So({children:e,session:t,...o}){let n=Ir(()=>typeof Response<"u"&&t instanceof Response?t.ok?void 0:null:yt(t),[t]);return bt(Ie,{...o,session:n,children:bt(kr,{className:o.className,children:e})})}function kr({className:e,children:t}){let{status:o}=Ee();return o==="unauthenticated"?e?bt("div",{className:e,children:t}):t:null}import{mfa as Ro,sanitizeRedirectUrl as Mo}from"@niledatabase/client";import{useState as ke,useEffect as Lr,useCallback as je}from"react";var Xe=e=>typeof e=="object"&&e!==null,Po=e=>e==="setup"||e==="challenge",Br=e=>{if(!Array.isArray(e))return;let t=e.filter(o=>typeof o=="string"&&o.trim().length>0);return t.length>0?t:void 0},Co=e=>!Xe(e)||e.method!=="authenticator"||!Po(e.scope)||typeof e.token!="string"?null:{method:"authenticator",token:e.token,scope:e.scope,otpauthUrl:typeof e.otpauthUrl=="string"?e.otpauthUrl:void 0,secret:typeof e.secret=="string"?e.secret:void 0,recoveryKeys:Br(e.recoveryKeys)},xo=e=>!Xe(e)||e.method!=="email"||!Po(e.scope)||typeof e.token!="string"?null:{method:"email",token:e.token,scope:e.scope,maskedEmail:typeof e.maskedEmail=="string"&&e.maskedEmail.trim().length>0?e.maskedEmail:void 0};var Ye="nile.mfa.challenge";function Ze(e){if(!(typeof window>"u"))try{window.sessionStorage.setItem(Ye,JSON.stringify(e))}catch{}}function Je(){if(typeof window>"u")return null;try{let e=window.sessionStorage.getItem(Ye);if(!e)return null;let t=JSON.parse(e);if(t&&typeof t=="object"&&typeof t.token=="string"&&(t.method==="email"||t.method==="authenticator")&&(t.scope==="setup"||t.scope==="challenge"))return{token:t.token,method:t.method,scope:t.scope,destination:typeof t.destination=="string"?t.destination:void 0}}catch{}return null}function xe(){if(!(typeof window>"u"))try{window.sessionStorage.removeItem(Ye)}catch{}}var No="/mfa/prompt",Do=({method:e,currentMethod:t,promptPath:o=No,onRedirect:n,onChallengeRedirect:r})=>{let[i,a]=ke(null),[s,l]=ke(null),[u,m]=ke(null),[d,g]=ke(!1),[c,p]=ke(!1),y=e==="authenticator"?Co:xo,S=je(v=>{let P=Mo(v);if(n){n(P);return}typeof window<"u"&&window.location.assign(P)},[n]),C=je(v=>{if(r){r(v);return}Ze(v);let P=new URLSearchParams({method:v.method,scope:v.scope});v.destination&&P.set("destination",v.destination);let I=Mo(o,{fallback:No}),N=I.includes("?")?"&":"?";S(`${I}${N}${P.toString()}`)},[S,r,o]),b=je(async()=>{g(!0),l(null),m(null);try{let v=await Ro({scope:"setup",method:e}),P=Fo(v);if(P){a(null),l("setup"),m(P);return}let I=vt(v);if(I){S(I);return}let N=y(v);if(!N){a(null),l("parseSetup");return}if(N.scope==="challenge"){C({token:N.token,method:N.method,scope:N.scope,destination:"maskedEmail"in N?N.maskedEmail:void 0});return}a(N)}catch{l("setup"),a(null)}finally{g(!1)}},[e,S,y,C]),E=je(async()=>{p(!0),l(null),m(null);try{let v=await Ro({method:e}),P=Fo(v);if(P){l("disable"),m(P);return}let I=vt(v);if(I){S(I);return}let N=y(v);if(!N){l("parseDisable");return}a(N)}catch{l("disable")}finally{p(!1)}},[e,S,y]);return Lr(()=>(l(null),m(null),a(null),()=>{a(null)}),[t]),{setup:i,loading:d||c,errorType:s,errorMessage:u,startSetup:b,startDisable:E}},vt=e=>Xe(e)&&typeof e.url=="string"||typeof Response<"u"&&e instanceof Response&&typeof e.url=="string"?e.url:null,Fo=e=>{let t=vt(e);if(!t)return null;try{let o=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",r=new URL(t,o).searchParams.get("error");if(r)return r}catch{return null}return null};import Pt from"react-qr-code";import{Copy as Tr,Download as Ur}from"lucide-react";import{useState as zr,useMemo as Or,useEffect as Ar}from"react";import{jsx as _,jsxs as et}from"react/jsx-runtime";function wt({setup:e,onError:t}){let[o,n]=zr("idle"),r=Or(()=>e.recoveryKeys?.join(`
|
|
28
|
+
`)??"",[e.recoveryKeys]);return Ar(()=>{n("idle")},[e.token]),_("div",{className:"mt-4 flex w-full flex-col items-center gap-3 text-left",children:et("div",{className:"w-full max-w-sm space-y-2",children:[_("p",{className:"text-sm font-medium",children:"Recovery codes"}),_("p",{className:"text-xs text-muted-foreground",children:"Store these somewhere safe. Use one if you lose your authenticator device."}),_("div",{className:"rounded-md border border-dashed bg-muted/30 p-4",children:_("ul",{className:"grid gap-2 font-mono text-sm",children:e.recoveryKeys?.map(i=>_("li",{children:i},i))})}),et("div",{className:"flex flex-wrap items-center gap-2",children:[et(R,{type:"button",size:"sm",onClick:async()=>{if(r){if(!("clipboard"in navigator)){n("error");return}try{await navigator.clipboard.writeText(r),n("copied")}catch{n("error")}}},children:[_(Tr,{className:"size-4","aria-hidden":"true"}),"Copy"]}),et(R,{type:"button",size:"sm",variant:"outline",onClick:()=>{if(r)try{let i=`Nile MFA recovery codes
|
|
29
29
|
|
|
30
|
-
`,s=new Blob([i,n],{type:"text/plain"}),a=URL.createObjectURL(s),l=document.createElement("a");l.href=a,l.download="nile-mfa-recovery-codes.txt",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a)}catch{t("We were unable to download the recovery keys. Please try again.")}}},q.createElement(en,{className:"size-4","aria-hidden":"true"}),"Download"),o==="copied"?q.createElement("span",{className:"text-xs text-muted-foreground"},"Recovery codes copied to clipboard."):o==="error"?q.createElement("span",{className:"text-xs text-destructive"},"Unable to copy automatically. Please copy the codes manually."):null)))}import*as w from"react";import{mfa as an,sanitizeRedirectUrl as ln}from"@niledatabase/client";import A,{useEffect as nn}from"react";import{mfa as sn}from"@niledatabase/client";function bt({token:e,scope:t,method:o,remove:r,onSuccess:n,onCancel:i}){let[s,a]=A.useState(""),[l,u]=A.useState(null),[c,d]=A.useState(!1),[g,m]=A.useState(!1),[p,v]=A.useState(""),M=A.useRef(null),F=A.useId(),x=A.useId(),B=A.useRef(null);nn(()=>(a(""),u(null),m(!1),d(!1),()=>{B.current&&(clearTimeout(B.current),B.current=null)}),[e]);let S=async I=>{if(I.preventDefault(),c||g)return;if(!e){u("Missing MFA challenge token. Please restart the sign-in flow.");return}let X=s.trim();if(!X.length){u("Enter your recovery code to continue.");return}d(!0),u(null);let pe=!1;try{let H=await sn({token:e,code:X,scope:t,method:o,remove:r});if(H?.ok){pe=!0,m(!0),Se();let Y=typeof H.recoveryCodesRemaining=="number"?H.recoveryCodesRemaining:null;v(Y!==null?`You have ${Y} recovery ${Y===1?"code":"codes"} remaining.`:"Recovery code verified."),B.current=setTimeout(()=>{n?.(H.scope??t)},2e3);return}if(H&&typeof H=="object"&&"url"in H){let Y=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",Be=new URL(String(H.url),Y);u(Be.searchParams.get("error")??"We couldn't verify that recovery code. Please try again.");return}u("We couldn't verify that recovery code. Please try again.")}catch{u("We ran into a problem verifying the code. Please try again.")}finally{pe||d(!1)}},N=I=>{a(I.target.value),l&&u(null)},L=c||g;return A.createElement("form",{className:"space-y-6",onSubmit:S},A.createElement("fieldset",{className:"flex flex-col gap-6",disabled:L},A.createElement("label",{htmlFor:F,className:"sr-only"},"Recovery code"),A.createElement(j,{id:F,ref:M,className:"h-14",type:"text",autoComplete:"one-time-code","aria-label":"Recovery code","aria-invalid":!!l,"aria-describedby":l?x:void 0,placeholder:"Enter a recovery code",value:s,onChange:N}),A.createElement(E,{className:"w-full",type:"submit",size:"lg",disabled:L},c?"Verifying...":"Submit")),A.createElement("div",{className:"flex justify-center"},A.createElement(E,{type:"button",variant:"link",className:"p-0 text-sm",onClick:i,disabled:L},"Use verification code instead")),l?A.createElement("p",{className:"text-sm font-medium text-destructive",id:x,role:"alert"},l):null,p?A.createElement("p",{className:"text-sm font-medium text-orange-600",role:"alert"},p):null)}var ce=6;function de({token:e,scope:t,method:o,remove:r,signInHref:n="/mfa",onSuccess:i}){let[s,a]=w.useState(Array(ce).fill("")),[l,u]=w.useState(e),[c,d]=w.useState(null),[g,m]=w.useState(null),[p,v]=w.useState(!1),[M,F]=w.useState(!1),x=w.useId(),B=w.useRef([]),S=ln(n,{fallback:"/mfa"});w.useEffect(()=>{M||B.current[0]?.focus()},[M]),w.useEffect(()=>{if(e){u(e);return}let D=Ke();D?.token?u(D.token):u("")},[e]);let N=D=>P=>{let K=P.target.value.replace(/\D+/g,"");if(!K.length){X(D,"");return}let te=K.at(-1)??"";X(D,te),D<ce-1&&B.current[D+1]?.focus()},L=D=>P=>{P.key==="Backspace"&&(s[D]?X(D,""):D>0&&(B.current[D-1]?.focus(),X(D-1,"")),P.preventDefault()),P.key==="ArrowLeft"&&D>0&&(B.current[D-1]?.focus(),P.preventDefault()),P.key==="ArrowRight"&&D<ce-1&&(B.current[D+1]?.focus(),P.preventDefault())},I=D=>{D.preventDefault();let P=D.clipboardData.getData("text").replace(/\D+/g,"").slice(0,ce).split("");if(!P.length)return;let K=[...s];for(let Le=0;Le<ce;Le+=1)K[Le]=P[Le]??"";a(K);let te=Math.min(P.length,ce-1);B.current[te]?.focus()},X=(D,P)=>{a(K=>{let te=[...K];return te[D]=P,te}),d(null),m(null)},pe=w.useMemo(()=>s.join(""),[s]),H=async D=>{if(D.preventDefault(),!l){d("Missing MFA challenge token. Please restart the sign-in flow.");return}if(pe.length!==ce){d("Enter the full 6-digit code to continue.");return}v(!0),d(null),m(null);try{let P=await an({token:l,code:pe,scope:t,method:o,remove:r});if(P?.ok)Se(),i?.(P.scope??t);else if(P&&typeof P=="object"&&"url"in P&&typeof P.url=="string"){let K=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",te=new URL(P.url,K);d(te.searchParams.get("error")??"We ran into a problem verifying the code. Please try again.")}else d("We ran into a problem verifying the code. Please try again.")}catch{d("We ran into a problem verifying the code. Please try again.")}finally{v(!1)}},Y=()=>{F(!1),a(Array(ce).fill("")),d(null),m(null)},Be=async()=>{M||(d(null),m(null),F(!0))};return w.createElement("div",{className:"space-y-6"},M?w.createElement(bt,{token:l,scope:t,method:o,remove:r,onSuccess:i,onCancel:Y}):w.createElement("form",{className:"space-y-6",onSubmit:H},w.createElement("fieldset",{className:"flex flex-col gap-6",disabled:p||M},w.createElement("div",{className:"flex justify-center gap-3"},s.map((D,P)=>w.createElement(j,{key:P,ref:K=>{B.current[P]=K},className:f("h-14 w-12 rounded-lg border border-input/80 bg-muted/40 text-center text-2xl font-medium tracking-[0.25em]","placeholder:text-muted-foreground/80 focus-visible:ring-2 focus-visible:ring-primary/40"),inputMode:"numeric",type:"text",autoComplete:"one-time-code","aria-label":`Digit ${P+1}`,"aria-invalid":!!c,"aria-describedby":c?x:void 0,pattern:"[0-9]*",maxLength:1,value:D,onChange:N(P),onKeyDown:L(P),onPaste:I}))),w.createElement(E,{className:"w-full",type:"submit",size:"lg",disabled:p},p?"Verifying...":"Submit")),c?w.createElement("div",{className:"flex flex-col gap-2"},w.createElement("p",{className:"text-sm font-medium text-destructive",id:x,role:"alert"},"Error: ",c),w.createElement(E,{variant:"outline",asChild:!0},w.createElement("a",{href:S},"Back to sign in"))):null),c==="Invalid MFA code"?w.createElement(E,{variant:"link",asChild:!0},w.createElement("a",{href:S},"Return to sign in")):null,M?null:w.createElement("div",{className:"flex justify-center"},w.createElement(E,{type:"button",variant:"link",className:"p-0 text-sm",onClick:Be,disabled:p||M},"Use a recovery code")),g?w.createElement("p",{className:"text-sm font-medium text-emerald-600",role:"status"},g):null)}function ho({setup:e,onError:t,onSuccess:o}){let r=vt.default?vt.default:vt;return fe.createElement("div",{className:"flex flex-col items-center gap-4 text-center"},e.otpauthUrl?fe.createElement(fe.Fragment,null,fe.createElement("div",{className:"rounded-md border border-border bg-background p-3"},fe.createElement(r,{value:e.otpauthUrl,size:192,className:"h-48 w-48"})),fe.createElement("p",{className:"text-sm text-muted-foreground"},"Scan the code with your authenticator app, then enter the 6-digit code below.")):null,e.recoveryKeys?fe.createElement(yt,{setup:e,onError:t,onSuccess:o}):null,fe.createElement(de,{token:e.token,scope:e.scope,method:e.method,onSuccess:o}))}import wt from"react";function yo({setup:e,onSuccess:t}){return wt.createElement("div",{className:"flex w-full max-w-sm flex-col items-center gap-3 text-center"},wt.createElement("p",{className:"text-sm text-muted-foreground"},e.maskedEmail?`We sent a 6-digit code to ${e.maskedEmail}. Enter it below to finish.`:"Check your email for a 6-digit code and enter it below to finish."),wt.createElement(de,{token:e.token,scope:e.scope,method:e.method,onSuccess:t}))}import xt from"react";function bo({payload:e,message:t,isEnrolled:o,signInHref:r,onSuccess:n}){return xt.createElement("div",{className:"flex w-full max-w-sm flex-col items-center gap-3 text-center"},xt.createElement("p",{className:"text-sm text-muted-foreground"},t),xt.createElement(de,{token:e.token,scope:e.scope,method:e.method,remove:o,signInHref:r,onSuccess:n}))}import h,{useCallback as Co,useEffect as Fn,useState as Et}from"react";import{useMutation as Dn}from"@tanstack/react-query";import{ArrowLeftRight as En,ChevronDown as In,Plus as Mo}from"lucide-react";import{useForm as kn}from"react-hook-form";import*as C from"react";import*as b from"@radix-ui/react-dropdown-menu";import{Check as un,ChevronRight as mn,Circle as cn}from"lucide-react";var vo=b.Root,St=C.forwardRef(({className:e,...t},o)=>C.createElement(b.Trigger,{ref:o,className:f("focus-visible:outline-hidden hover:bg-accent focus:bg-accent flex flex-row gap-2 items-center justify-between px-4 py-2 rounded-lg border data-disabled:pointer-events-none data-disabled:opacity-50",e),...t}));St.displayName=b.Trigger.displayName;var dn=C.forwardRef(({className:e,inset:t,children:o,...r},n)=>C.createElement(b.SubTrigger,{ref:n,className:f("flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-hidden focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r},o,C.createElement(mn,{className:"ml-auto"})));dn.displayName=b.SubTrigger.displayName;var fn=C.forwardRef(({className:e,...t},o)=>C.createElement(b.SubContent,{ref:o,className:f("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));fn.displayName=b.SubContent.displayName;var Pt=C.forwardRef(({className:e,sideOffset:t=4,...o},r)=>C.createElement(b.Portal,null,C.createElement(b.Content,{ref:r,sideOffset:t,className:f("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...o})));Pt.displayName=b.Content.displayName;var _e=C.forwardRef(({className:e,inset:t,active:o,...r},n)=>C.createElement(b.Item,{ref:n,className:f("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",o&&"bg-accent text-accent-foreground",e),...r}));_e.displayName=b.Item.displayName;var pn=C.forwardRef(({className:e,children:t,checked:o,...r},n)=>C.createElement(b.CheckboxItem,{ref:n,className:f("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",e),checked:o,...r},C.createElement("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center"},C.createElement(b.ItemIndicator,null,C.createElement(un,{className:"h-4 w-4"}))),t));pn.displayName=b.CheckboxItem.displayName;var gn=C.forwardRef(({className:e,children:t,...o},r)=>C.createElement(b.RadioItem,{ref:r,className:f("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",e),...o},C.createElement("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center"},C.createElement(b.ItemIndicator,null,C.createElement(cn,{className:"h-2 w-2 fill-current"}))),t));gn.displayName=b.RadioItem.displayName;var hn=C.forwardRef(({className:e,inset:t,...o},r)=>C.createElement(b.Label,{ref:r,className:f("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...o}));hn.displayName=b.Label.displayName;var Ct=C.forwardRef(({className:e,...t},o)=>C.createElement(b.Separator,{ref:o,className:f("-mx-1 my-1 h-px bg-muted",e),...t}));Ct.displayName=b.Separator.displayName;var yn=({className:e,...t})=>C.createElement("span",{className:f("ml-auto text-xs tracking-widest opacity-60",e),...t});yn.displayName="DropdownMenuShortcut";import*as V from"react";import*as T from"@radix-ui/react-dialog";import{X as bn}from"lucide-react";var wo=T.Root,xo=T.Trigger,vn=T.Portal;var So=V.forwardRef(({className:e,...t},o)=>V.createElement(T.Overlay,{ref:o,className:f("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));So.displayName=T.Overlay.displayName;var Mt=V.forwardRef(({className:e,children:t,...o},r)=>V.createElement(vn,null,V.createElement(So,null),V.createElement(T.Content,{ref:r,className:f("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...o},t,V.createElement(T.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"},V.createElement(bn,{className:"h-4 w-4"}),V.createElement("span",{className:"sr-only"},"Close")))));Mt.displayName=T.Content.displayName;var Nt=({className:e,...t})=>V.createElement("div",{className:f("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Nt.displayName="DialogHeader";var wn=({className:e,...t})=>V.createElement("div",{className:f("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});wn.displayName="DialogFooter";var Ft=V.forwardRef(({className:e,...t},o)=>V.createElement(T.Title,{ref:o,className:f("text-lg font-semibold leading-none tracking-tight",e),...t}));Ft.displayName=T.Title.displayName;var Dt=V.forwardRef(({className:e,...t},o)=>V.createElement(T.Description,{ref:o,className:f("text-sm text-muted-foreground",e),...t}));Dt.displayName=T.Description.displayName;import xn,{useCallback as Sn,useEffect as Pn}from"react";import{useQuery as Cn}from"@tanstack/react-query";var Po="nile.tenant-id";function Ee(e){let{disableQuery:t,tenants:o,baseUrl:r="",basePath:n,auth:i,init:s}=e,a=z(e.client);return Cn({queryKey:["tenants",r,n,e.fetchUrl],queryFn:async()=>{let u=await we(e.fetchUrl??"/tenants",{headers:{"content-type":"application/json"}},{auth:i,init:s,baseUrl:r,basePath:n,fetchUrl:e.fetchUrl});if(!u.ok)throw new Error("Failed to fetch tenants");return u.json()},enabled:t!==!0,initialData:o},a)}function Xe(e){let t=e?.useCookie!==!1,[o,r]=xn.useState(e?.activeTenant??e?.tenant?.id),{refetch:n}=Ee({...e,disableQuery:!0});Pn(()=>{if(!o){let a=t?Mn(Po):null;a?r(a):!e?.disableQuery&&!e?.tenants?.length&&n()}},[n,o,t,e?.disableQuery,e?.tenants?.length]);let{onTenantChange:i}=e??{},s=Sn(a=>{r(a),t&&Nn(Po,a),i?.(a)},[i,t]);return[o,s]}var Mn=e=>{if(typeof document>"u")return null;let t=document.cookie.split(";");for(let o of t){let r=o.trim(),n=r.indexOf("=");if(n===-1)continue;if(r.slice(0,n).trim()===e){let s=r.slice(n+1);try{return decodeURIComponent(s)}catch{return s}}}return null},Nn=(e,t)=>{if(typeof document>"u")return;let o=typeof window<"u"&&window.location?.protocol==="https:"?"; Secure":"";document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=/; SameSite=Lax${o}`};function Fo(e){let{client:t}=e??{};return h.createElement(Q,{client:t},h.createElement(Bn,{...e}))}function Bn(e){let{data:t=e.tenants??[],isLoading:o,refetch:r}=Ee(e),{buttonText:n="Create an organization",emptyText:i="You are not part of an organization."}=e,[s,a]=Xe(e),[l,u]=Et(!1),[c,d]=Et(!1),g=t.find(m=>m.id===s);return Fn(()=>{!e.tenants?.length&&t?.length>0&&!g&&a(t[0].id)},[e.tenants?.length,t]),!o&&t.length===0?h.createElement("div",{className:f("flex flex-col items-center gap-2",e.className)},h.createElement("p",null,i),h.createElement(No,{...e,onSuccess:m=>{a(m.id),u(!1),r()},trigger:h.createElement(E,{type:"button"},h.createElement(Mo,{size:18})," ",n)})):h.createElement("div",null,h.createElement("div",{className:f(e.className)},h.createElement("div",{className:"text-sm pb-1.5 opacity-70 flex flex-row gap-1 items-center"},h.createElement(En,{size:14}),"Switch organization"),h.createElement("div",{className:"flex flex-row w-full flex-1 items-center gap-1"},h.createElement(vo,{open:l,onOpenChange:u},h.createElement(St,{className:"group w-80 font-medium text-sm",disabled:!g?.name,onClick:()=>{u(!0)}},g?.name??"Loading...",h.createElement(In,{className:"transition-transform duration-200 ease-in-out group-data-[state=open]:rotate-180"})),h.createElement(Pt,{className:"flex flex-col gap-0.5 max-h-96 overflow-auto custom-scrollbar w-80"},t?.map(m=>h.createElement(_e,{key:m.id,onClick:()=>a(m.id),active:m.id===g?.id},m.name)),h.createElement(Ct,null),h.createElement(_e,{onSelect:m=>{m.preventDefault(),u(!1),d(!0)}},h.createElement("span",{className:"flex items-center gap-1 mx-auto"},h.createElement(Mo,{size:18})," Create new organization")))),h.createElement(No,{...e,open:c,onOpenChange:d,onSuccess:m=>{u(!1),d(!1),a(m.id),r()}}))))}function No(e){let[t,o]=Et(!1),r=e.open!==void 0,n=r?e.open:t,{trigger:i,beforeMutate:s,onSuccess:a,onError:l,auth:u,init:c,baseUrl:d,basePath:g}=e,m=z(e.client),p=kn({defaultValues:{name:""}}),v=Dn({mutationFn:async x=>{let B={...x,name:x.name.trim()},N=(s&&s(B))??B,L=await we(e?.fetchUrl??"/tenants",{method:"POST",body:JSON.stringify(N)},{auth:u,init:c,baseUrl:d,basePath:g,fetchUrl:e.fetchUrl});if(!L.ok){let I=await L.text().catch(()=>"");throw new Error(I||"Failed to create organization")}return L.json()},onSuccess:async x=>{p.reset({name:""}),r||o(!1),e.onOpenChange?.(!1),a&&a(x)},onError:l},m),M=Co(x=>{r||o(x),e.onOpenChange?.(x),x||(p.reset({name:""}),v.reset())},[p,r,v,e]),F=Co(x=>{v.mutate(x)},[v]);return h.createElement(wo,{open:n,onOpenChange:M},i?h.createElement(xo,{asChild:!0},i):null,h.createElement(Mt,null,h.createElement(Nt,null,h.createElement(Ft,null,"Create an organization"),h.createElement(Dt,null,"An organization is a group of users.")),h.createElement(W,{...p},h.createElement("form",{onSubmit:p.handleSubmit(F)},h.createElement(ge,{control:p.control,name:"name",rules:{validate:x=>x.trim().length>0||"Organization name is required."},render:({field:x})=>h.createElement(oe,null,h.createElement(re,null,"Name"),h.createElement(ne,null,h.createElement(j,{placeholder:"Organization name",...x,autoFocus:!0})),h.createElement(he,null,"This is the name of your organization."),h.createElement(ye,null))}),v.error?h.createElement("p",{role:"alert",className:"text-sm text-destructive py-1"},v.error instanceof Error?v.error.message:"Failed to create organization"):null,h.createElement(E,{type:"submit",className:"py-2",loading:v.isPending},"Submit")))))}import{BadgeCheck as Do,CalendarCheck as Tn,CircleUserRound as Un,Mail as zn}from"lucide-react";import U,{useMemo as On}from"react";import{useQuery as Ln}from"@tanstack/react-query";function Ye(e){let{baseUrl:t="",basePath:o,fetchUrl:r,client:n,user:i,auth:s,init:a}=e??{},l=z(n),{data:u,isLoading:c}=Ln({queryKey:["me",t,o,r],queryFn:async()=>{let d=await we(r??"/me",void 0,{auth:s,init:a,baseUrl:t,basePath:o,fetchUrl:r});if(!d.ok)throw new Error(`Failed to fetch user (${d.status})`);return await d.json()},enabled:i==null},l);return i||u?i??u??null:s&&!(i&&c)?s.state?.session?.user??u??null:null}function Eo(e){return U.createElement(Q,{client:e.client},U.createElement(An,{...e}))}function Rn(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{dateStyle:"medium",timeStyle:"short",timeZone:"UTC"}).format(t)}function An(e){let t=Ye(e),o=U.useMemo(()=>t&&typeof t=="object"&&"picture"in t&&t.picture?U.createElement("img",{src:t.picture,alt:`${t.name??t.email} profile picture`,referrerPolicy:"no-referrer"}):e.profilePicturePlaceholder?e.profilePicturePlaceholder:U.createElement("div",{className:"drop-shadow-md",style:{background:"linear-gradient(90deg, #F4C587, #D6D3E9, #99D2EC)"}},U.createElement(Un,{size:100,className:"opacity-70 stroke-black",style:{strokeWidth:".5px"}})),[t,e.profilePicturePlaceholder]),r=On(()=>{if(t?.name)return t?.name;let n="";return t?.givenName&&(n=t?.givenName),t?.familyName&&(n=`${n} ${t?.familyName}`),n},[t?.familyName,t?.givenName,t?.name]);return t?U.createElement("div",{className:f(e.className,"flex flex-col gap-2 items-center")},U.createElement("div",{className:"flex flex-col gap-5 pb-2 items-center"},U.createElement("div",{className:"flex flex-col gap-2 items-center w-36 mx-auto"},U.createElement("div",{className:"rounded-full border border-background overflow-hidden shadow-md"},o)),U.createElement("div",{className:"font-bold flex flex-row gap-1 capitalize"},r)),U.createElement("div",{className:"flex flex-row gap-5 justify-between w-full"},U.createElement("div",{className:"flex flex-row gap-2 text-sm items-center w-36"},U.createElement(zn,{size:14}),"Email:"),U.createElement("div",{className:"flex flex-row gap-1 items-center"},t.emailVerified?U.createElement(Do,{className:"stroke-white fill-green-700",size:14}):U.createElement(Do,{className:"opacity-40",size:14}),t.email," ")),t.created?U.createElement("div",{className:"flex flex-row gap-5 justify-between w-full"},U.createElement("div",{className:"flex flex-row gap-2 text-sm items-center w-36"},U.createElement(Tn,{size:14}),"Created:"),Rn(t.created)):null):"Loading..."}import kt from"react";import{useForm as Qn}from"react-hook-form";import ve from"react";import{useMutation as Io}from"@tanstack/react-query";import{resetPassword as Hn,forgotPassword as Vn}from"@niledatabase/client";function Ie(e){let{auth:t,baseUrl:o="",beforeMutate:r,client:n,callbackUrl:i,fetchUrl:s,init:a,onError:l,onSuccess:u,redirect:c=!1}=e??{},d=z(n),g=Io({mutationFn:async m=>{let v=(r&&r(m))??m;return await Hn({auth:t,baseUrl:o,callbackUrl:i,fetchUrl:s,init:a,redirect:c,...v})},onSuccess:m=>{u&&u(m)},onError:l},d);return Ue(e),g}function ko(e){return Ie(e).mutate}function Bo(e){let{auth:t,baseUrl:o="",beforeMutate:r,callbackUrl:n,fetchUrl:i,init:s,client:a,onError:l,onSuccess:u,redirect:c=!1}=e??{},d=z(a),g=Io({mutationFn:async m=>{let v=(r&&r(m))??m;return await Vn({auth:t,baseUrl:o,callbackUrl:n,fetchUrl:i,init:s,redirect:c,...v})},onSuccess:m=>{u&&u(m)},onError:l},d);return Ue(e),g}function It(e){return ve.createElement(Q,{client:e.client},ve.createElement(qn,{...e}))}function qn(e){let{defaultValues:t,buttonText:o="Reset password",...r}=e,n=Qn({defaultValues:{email:"",...t}}),i=Ie({...r,redirect:!0});return ve.createElement(W,{...n},ve.createElement("form",{className:"py-2",onSubmit:n.handleSubmit(({email:s})=>{i.mutate({email:s})})},ve.createElement(Z,null),!e.onError&&i.error?ve.createElement("p",{role:"alert",className:"text-sm font-medium text-destructive"},i.error instanceof Error?i.error.message:"Password reset request failed"):null,ve.createElement(E,{type:"submit",loading:i.isPending},o)))}function Bt(e){return kt.createElement("div",{className:"flex flex-col gap-4"},kt.createElement("h2",{className:"font-sans text-3xl"},"Request password reset"),kt.createElement(It,{...e}))}import ke from"react";import{useForm as jn}from"react-hook-form";import O,{useEffect as Wn,useState as $n}from"react";function Lt(e){return O.createElement(Q,{client:e.client},O.createElement(Kn,{...e}))}function Kn(e){let{defaultValues:t,mode:o,buttonText:r="Update password",...n}=e,i=jn({defaultValues:{email:"",password:"",confirmPassword:"",...t}}),s=Bo(n),a=Ie(n),l=i.watch("password"),u=i.watch("confirmPassword"),[c,d]=$n(!0),g=s.isPending||a.isPending,m=s.error||a.error;return Wn(()=>{i.clearErrors(),!l||!u?d(!0):l!==u?(i.setError("confirmPassword",{message:"Passwords must match."}),d(!0)):d(!1)},[l,u,i]),O.createElement(W,{...i},O.createElement("form",{onSubmit:i.handleSubmit(({email:p,password:v})=>{o==="forgot"||!o&&!p?s.mutate({password:v}):a.mutate({email:p,password:v})}),className:"py-2"},t?.email?O.createElement(ge,{control:i.control,name:"email",render:({field:p})=>O.createElement(oe,null,O.createElement(re,null,"Email address"),O.createElement(ne,null,O.createElement(j,{...p,disabled:!0})))}):null,O.createElement(be,{autoComplete:"new-password"}),O.createElement(ge,{control:i.control,name:"confirmPassword",render:({field:p})=>O.createElement(oe,null,O.createElement(re,null,"Confirm password"),O.createElement(ne,null,O.createElement(j,{placeholder:"Password",...p,type:"password",autoComplete:"new-password"})),O.createElement(he,null,"Confirm your new password"),O.createElement(ye,null))}),!e.onError&&m?O.createElement("p",{role:"alert",className:"text-sm font-medium text-destructive"},m instanceof Error?m.message:"Password update failed"):null,O.createElement(E,{type:"submit",loading:g,disabled:Object.keys(i.formState.errors).length>0||c},r)))}function Tt(e){return ke.createElement(Q,{client:e.client},ke.createElement(Gn,{...e}))}function Gn({className:e,...t}){return ke.createElement("div",{className:f(e,"flex flex-col gap-4")},ke.createElement("h2",{className:"font-sans text-3xl"},"Reset password"),ke.createElement(Lt,{...t}))}import{getSession as bm,getCsrfToken as vm,getProviders as wm,signIn as xm,signOut as Sm,auth as Pm,Authorizer as Cm}from"@niledatabase/client";export{Cm as Authorizer,ur as Azure,cr as Discord,Z as Email,rt as EmailSignIn,jt as EmailSignInButton,fr as GitHub,$t as Google,gr as HubSpot,yr as LinkedIn,ho as MultiFactorAuthenticator,bo as MultiFactorChallenge,yo as MultiFactorEmail,de as MultiFactorVerify,Pr as Okta,be as Password,Tt as PasswordResetForm,Bt as PasswordResetRequestForm,Me as SessionContext,Fe as SessionProvider,mt as SignInForm,Rr as SignOutButton,at as SignUpForm,io as SignedIn,so as SignedOut,vr as Slack,Fo as TenantSelector,Eo as UserInfo,xr as X,Pm as auth,Se as clearMfaChallenge,vm as getCsrfToken,wm as getProviders,bm as getSession,Ke as readMfaChallenge,xm as signIn,Sm as signOut,$e as storeMfaChallenge,Qt as useEmailSignIn,Ye as useMe,go as useMultiFactor,ko as useResetPassword,Ne as useSession,qe as useSignIn,Qe as useSignUp,Xe as useTenantId,Ee as useTenants};
|
|
30
|
+
`,a=new Blob([i,r],{type:"text/plain"}),s=URL.createObjectURL(a),l=document.createElement("a");l.href=s,l.download="nile-mfa-recovery-codes.txt",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(s)}catch{t("We were unable to download the recovery keys. Please try again.")}},children:[_(Ur,{className:"size-4","aria-hidden":"true"}),"Download"]}),o==="copied"?_("span",{className:"text-xs text-muted-foreground",children:"Recovery codes copied to clipboard."}):o==="error"?_("span",{className:"text-xs text-destructive",children:"Unable to copy automatically. Please copy the codes manually."}):null]})]})})}import*as z from"react";import{mfa as Qr,sanitizeRedirectUrl as qr}from"@niledatabase/client";import te,{useEffect as Hr}from"react";import{mfa as Vr}from"@niledatabase/client";import{jsx as ve,jsxs as Eo}from"react/jsx-runtime";function St({token:e,scope:t,method:o,remove:n,onSuccess:r,onCancel:i}){let[a,s]=te.useState(""),[l,u]=te.useState(null),[m,d]=te.useState(!1),[g,c]=te.useState(!1),[p,y]=te.useState(""),S=te.useRef(null),C=te.useId(),b=te.useId(),E=te.useRef(null);Hr(()=>(s(""),u(null),c(!1),d(!1),()=>{E.current&&(clearTimeout(E.current),E.current=null)}),[e]);let v=async N=>{if(N.preventDefault(),m||g)return;if(!e){u("Missing MFA challenge token. Please restart the sign-in flow.");return}let Y=a.trim();if(!Y.length){u("Enter your recovery code to continue.");return}d(!0),u(null);let ce=!1;try{let T=await Vr({token:e,code:Y,scope:t,method:o,remove:n});if(T?.ok){ce=!0,c(!0),xe();let Z=typeof T.recoveryCodesRemaining=="number"?T.recoveryCodesRemaining:null;y(Z!==null?`You have ${Z} recovery ${Z===1?"code":"codes"} remaining.`:"Recovery code verified."),E.current=setTimeout(()=>{r?.(T.scope??t)},2e3);return}if(T&&typeof T=="object"&&"url"in T){let Z=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",Oe=new URL(String(T.url),Z);u(Oe.searchParams.get("error")??"We couldn't verify that recovery code. Please try again.");return}u("We couldn't verify that recovery code. Please try again.")}catch{u("We ran into a problem verifying the code. Please try again.")}finally{ce||d(!1)}},P=N=>{s(N.target.value),l&&u(null)},I=m||g;return Eo("form",{className:"space-y-6",onSubmit:v,children:[Eo("fieldset",{className:"flex flex-col gap-6",disabled:I,children:[ve("label",{htmlFor:C,className:"sr-only",children:"Recovery code"}),ve(Q,{id:C,ref:S,className:"h-14",type:"text",autoComplete:"one-time-code","aria-label":"Recovery code","aria-invalid":!!l,"aria-describedby":l?b:void 0,placeholder:"Enter a recovery code",value:a,onChange:P}),ve(R,{className:"w-full",type:"submit",size:"lg",disabled:I,children:m?"Verifying...":"Submit"})]}),ve("div",{className:"flex justify-center",children:ve(R,{type:"button",variant:"link",className:"p-0 text-sm",onClick:i,disabled:I,children:"Use verification code instead"})}),l?ve("p",{className:"text-sm font-medium text-destructive",id:b,role:"alert",children:l}):null,p?ve("p",{className:"text-sm font-medium text-orange-600",role:"alert",children:p}):null]})}import{jsx as G,jsxs as Be}from"react/jsx-runtime";var se=6;function le({token:e,scope:t,method:o,remove:n,signInHref:r="/mfa",onSuccess:i}){let[a,s]=z.useState(Array(se).fill("")),[l,u]=z.useState(e),[m,d]=z.useState(null),[g,c]=z.useState(null),[p,y]=z.useState(!1),[S,C]=z.useState(!1),b=z.useId(),E=z.useRef([]),v=qr(r,{fallback:"/mfa"});z.useEffect(()=>{S||E.current[0]?.focus()},[S]),z.useEffect(()=>{if(e){u(e);return}let x=Je();x?.token?u(x.token):u("")},[e]);let P=x=>w=>{let $=w.target.value.replace(/\D+/g,"");if(!$.length){Y(x,"");return}let oe=$.at(-1)??"";Y(x,oe),x<se-1&&E.current[x+1]?.focus()},I=x=>w=>{w.key==="Backspace"&&(a[x]?Y(x,""):x>0&&(E.current[x-1]?.focus(),Y(x-1,"")),w.preventDefault()),w.key==="ArrowLeft"&&x>0&&(E.current[x-1]?.focus(),w.preventDefault()),w.key==="ArrowRight"&&x<se-1&&(E.current[x+1]?.focus(),w.preventDefault())},N=x=>{x.preventDefault();let w=x.clipboardData.getData("text").replace(/\D+/g,"").slice(0,se).split("");if(!w.length)return;let $=[...a];for(let Ae=0;Ae<se;Ae+=1)$[Ae]=w[Ae]??"";s($);let oe=Math.min(w.length,se-1);E.current[oe]?.focus()},Y=(x,w)=>{s($=>{let oe=[...$];return oe[x]=w,oe}),d(null),c(null)},ce=z.useMemo(()=>a.join(""),[a]),T=async x=>{if(x.preventDefault(),!l){d("Missing MFA challenge token. Please restart the sign-in flow.");return}if(ce.length!==se){d("Enter the full 6-digit code to continue.");return}y(!0),d(null),c(null);try{let w=await Qr({token:l,code:ce,scope:t,method:o,remove:n});if(w?.ok)xe(),i?.(w.scope??t);else if(w&&typeof w=="object"&&"url"in w&&typeof w.url=="string"){let $=typeof window<"u"&&window.location?.origin?window.location.origin:"http://localhost",oe=new URL(w.url,$);d(oe.searchParams.get("error")??"We ran into a problem verifying the code. Please try again.")}else d("We ran into a problem verifying the code. Please try again.")}catch{d("We ran into a problem verifying the code. Please try again.")}finally{y(!1)}},Z=()=>{C(!1),s(Array(se).fill("")),d(null),c(null)},Oe=async()=>{S||(d(null),c(null),C(!0))};return Be("div",{className:"space-y-6",children:[S?G(St,{token:l,scope:t,method:o,remove:n,onSuccess:i,onCancel:Z}):Be("form",{className:"space-y-6",onSubmit:T,children:[Be("fieldset",{className:"flex flex-col gap-6",disabled:p||S,children:[G("div",{className:"flex justify-center gap-3",children:a.map((x,w)=>G(Q,{ref:$=>{E.current[w]=$},className:f("h-14 w-12 rounded-lg border border-input/80 bg-muted/40 text-center text-2xl font-medium tracking-[0.25em]","placeholder:text-muted-foreground/80 focus-visible:ring-2 focus-visible:ring-primary/40"),inputMode:"numeric",type:"text",autoComplete:"one-time-code","aria-label":`Digit ${w+1}`,"aria-invalid":!!m,"aria-describedby":m?b:void 0,pattern:"[0-9]*",maxLength:1,value:x,onChange:P(w),onKeyDown:I(w),onPaste:N},w))}),G(R,{className:"w-full",type:"submit",size:"lg",disabled:p,children:p?"Verifying...":"Submit"})]}),m?Be("div",{className:"flex flex-col gap-2",children:[Be("p",{className:"text-sm font-medium text-destructive",id:b,role:"alert",children:["Error: ",m]}),G(R,{variant:"outline",asChild:!0,children:G("a",{href:v,children:"Back to sign in"})})]}):null]}),m==="Invalid MFA code"?G(R,{variant:"link",asChild:!0,children:G("a",{href:v,children:"Return to sign in"})}):null,S?null:G("div",{className:"flex justify-center",children:G(R,{type:"button",variant:"link",className:"p-0 text-sm",onClick:Oe,disabled:p||S,children:"Use a recovery code"})}),g?G("p",{className:"text-sm font-medium text-emerald-600",role:"status",children:g}):null]})}import{Fragment as Wr,jsx as Le,jsxs as Io}from"react/jsx-runtime";function ko({setup:e,onError:t,onSuccess:o}){let n=Pt.default?Pt.default:Pt;return Io("div",{className:"flex flex-col items-center gap-4 text-center",children:[e.otpauthUrl?Io(Wr,{children:[Le("div",{className:"rounded-md border border-border bg-background p-3",children:Le(n,{value:e.otpauthUrl,size:192,className:"h-48 w-48"})}),Le("p",{className:"text-sm text-muted-foreground",children:"Scan the code with your authenticator app, then enter the 6-digit code below."})]}):null,e.recoveryKeys?Le(wt,{setup:e,onError:t,onSuccess:o}):null,Le(le,{token:e.token,scope:e.scope,method:e.method,onSuccess:o})]})}import{jsx as Bo,jsxs as $r}from"react/jsx-runtime";function Lo({setup:e,onSuccess:t}){return $r("div",{className:"flex w-full max-w-sm flex-col items-center gap-3 text-center",children:[Bo("p",{className:"text-sm text-muted-foreground",children:e.maskedEmail?`We sent a 6-digit code to ${e.maskedEmail}. Enter it below to finish.`:"Check your email for a 6-digit code and enter it below to finish."}),Bo(le,{token:e.token,scope:e.scope,method:e.method,onSuccess:t})]})}import{jsx as To,jsxs as Kr}from"react/jsx-runtime";function Uo({payload:e,message:t,isEnrolled:o,signInHref:n,onSuccess:r}){return Kr("div",{className:"flex w-full max-w-sm flex-col items-center gap-3 text-center",children:[To("p",{className:"text-sm text-muted-foreground",children:t}),To(le,{token:e.token,scope:e.scope,method:e.method,remove:o,signInHref:n,onSuccess:r})]})}import{useCallback as Qo,useEffect as mi,useState as kt}from"react";import{useMutation as di}from"@tanstack/react-query";import{ArrowLeftRight as fi,ChevronDown as pi,Plus as qo}from"lucide-react";import{useForm as gi}from"react-hook-form";import*as X from"react";import*as h from"@radix-ui/react-dropdown-menu";import{Check as Gr,ChevronRight as _r,Circle as Xr}from"lucide-react";import{jsx as A,jsxs as Mt}from"react/jsx-runtime";var zo=h.Root,Ct=X.forwardRef(({className:e,...t},o)=>A(h.Trigger,{ref:o,className:f("focus-visible:outline-hidden hover:bg-accent focus:bg-accent flex flex-row gap-2 items-center justify-between px-4 py-2 rounded-lg border data-disabled:pointer-events-none data-disabled:opacity-50",e),...t}));Ct.displayName=h.Trigger.displayName;var Yr=X.forwardRef(({className:e,inset:t,children:o,...n},r)=>Mt(h.SubTrigger,{ref:r,className:f("flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-hidden focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...n,children:[o,A(_r,{className:"ml-auto"})]}));Yr.displayName=h.SubTrigger.displayName;var Zr=X.forwardRef(({className:e,...t},o)=>A(h.SubContent,{ref:o,className:f("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));Zr.displayName=h.SubContent.displayName;var xt=X.forwardRef(({className:e,sideOffset:t=4,...o},n)=>A(h.Portal,{children:A(h.Content,{ref:n,sideOffset:t,className:f("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...o})}));xt.displayName=h.Content.displayName;var tt=X.forwardRef(({className:e,inset:t,active:o,...n},r)=>A(h.Item,{ref:r,className:f("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",o&&"bg-accent text-accent-foreground",e),...n}));tt.displayName=h.Item.displayName;var Jr=X.forwardRef(({className:e,children:t,checked:o,...n},r)=>Mt(h.CheckboxItem,{ref:r,className:f("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",e),checked:o,...n,children:[A("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:A(h.ItemIndicator,{children:A(Gr,{className:"h-4 w-4"})})}),t]}));Jr.displayName=h.CheckboxItem.displayName;var jr=X.forwardRef(({className:e,children:t,...o},n)=>Mt(h.RadioItem,{ref:n,className:f("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",e),...o,children:[A("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:A(h.ItemIndicator,{children:A(Xr,{className:"h-2 w-2 fill-current"})})}),t]}));jr.displayName=h.RadioItem.displayName;var ei=X.forwardRef(({className:e,inset:t,...o},n)=>A(h.Label,{ref:n,className:f("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...o}));ei.displayName=h.Label.displayName;var Rt=X.forwardRef(({className:e,...t},o)=>A(h.Separator,{ref:o,className:f("-mx-1 my-1 h-px bg-muted",e),...t}));Rt.displayName=h.Separator.displayName;var ti=({className:e,...t})=>A("span",{className:f("ml-auto text-xs tracking-widest opacity-60",e),...t});ti.displayName="DropdownMenuShortcut";import*as Te from"react";import*as k from"@radix-ui/react-dialog";import{X as oi}from"lucide-react";import{jsx as ue,jsxs as Nt}from"react/jsx-runtime";var Oo=k.Root,Ao=k.Trigger,ni=k.Portal;var Ho=Te.forwardRef(({className:e,...t},o)=>ue(k.Overlay,{ref:o,className:f("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));Ho.displayName=k.Overlay.displayName;var Ft=Te.forwardRef(({className:e,children:t,...o},n)=>Nt(ni,{children:[ue(Ho,{}),Nt(k.Content,{ref:n,className:f("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...o,children:[t,Nt(k.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[ue(oi,{className:"h-4 w-4"}),ue("span",{className:"sr-only",children:"Close"})]})]})]}));Ft.displayName=k.Content.displayName;var Dt=({className:e,...t})=>ue("div",{className:f("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Dt.displayName="DialogHeader";var ri=({className:e,...t})=>ue("div",{className:f("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});ri.displayName="DialogFooter";var Et=Te.forwardRef(({className:e,...t},o)=>ue(k.Title,{ref:o,className:f("text-lg font-semibold leading-none tracking-tight",e),...t}));Et.displayName=k.Title.displayName;var It=Te.forwardRef(({className:e,...t},o)=>ue(k.Description,{ref:o,className:f("text-sm text-muted-foreground",e),...t}));It.displayName=k.Description.displayName;import ii,{useCallback as ai,useEffect as si}from"react";import{useQuery as li}from"@tanstack/react-query";var Vo="nile.tenant-id";function Ue(e){let{disableQuery:t,tenants:o,baseUrl:n="",basePath:r,auth:i,init:a}=e,s=B(e.client);return li({queryKey:["tenants",n,r,e.fetchUrl],queryFn:async()=>{let u=await Se(e.fetchUrl??"/tenants",{headers:{"content-type":"application/json"}},{auth:i,init:a,baseUrl:n,basePath:r,fetchUrl:e.fetchUrl});if(!u.ok)throw new Error("Failed to fetch tenants");return u.json()},enabled:t!==!0,initialData:o},s)}function ot(e){let t=e?.useCookie!==!1,[o,n]=ii.useState(e?.activeTenant??e?.tenant?.id),{refetch:r}=Ue({...e,disableQuery:!0});si(()=>{if(!o){let s=t?ui(Vo):null;s?n(s):!e?.disableQuery&&!e?.tenants?.length&&r()}},[r,o,t,e?.disableQuery,e?.tenants?.length]);let{onTenantChange:i}=e??{},a=ai(s=>{n(s),t&&ci(Vo,s),i?.(s)},[i,t]);return[o,a]}var ui=e=>{if(typeof document>"u")return null;let t=document.cookie.split(";");for(let o of t){let n=o.trim(),r=n.indexOf("=");if(r===-1)continue;if(n.slice(0,r).trim()===e){let a=n.slice(r+1);try{return decodeURIComponent(a)}catch{return a}}}return null},ci=(e,t)=>{if(typeof document>"u")return;let o=typeof window<"u"&&window.location?.protocol==="https:"?"; Secure":"";document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=/; SameSite=Lax${o}`};import{jsx as M,jsxs as V}from"react/jsx-runtime";function $o(e){let{client:t}=e??{};return M(U,{client:t,children:M(hi,{...e})})}function hi(e){let{data:t=e.tenants??[],isLoading:o,refetch:n}=Ue(e),{buttonText:r="Create an organization",emptyText:i="You are not part of an organization."}=e,[a,s]=ot(e),[l,u]=kt(!1),[m,d]=kt(!1),g=t.find(c=>c.id===a);return mi(()=>{!e.tenants?.length&&t?.length>0&&!g&&s(t[0].id)},[e.tenants?.length,t]),!o&&t.length===0?V("div",{className:f("flex flex-col items-center gap-2",e.className),children:[M("p",{children:i}),M(Wo,{...e,onSuccess:c=>{s(c.id),u(!1),n()},trigger:V(R,{type:"button",children:[M(qo,{size:18})," ",r]})})]}):M("div",{children:V("div",{className:f(e.className),children:[V("div",{className:"text-sm pb-1.5 opacity-70 flex flex-row gap-1 items-center",children:[M(fi,{size:14}),"Switch organization"]}),V("div",{className:"flex flex-row w-full flex-1 items-center gap-1",children:[V(zo,{open:l,onOpenChange:u,children:[V(Ct,{className:"group w-80 font-medium text-sm",disabled:!g?.name,onClick:()=>{u(!0)},children:[g?.name??"Loading...",M(pi,{className:"transition-transform duration-200 ease-in-out group-data-[state=open]:rotate-180"})]}),V(xt,{className:"flex flex-col gap-0.5 max-h-96 overflow-auto custom-scrollbar w-80",children:[t?.map(c=>M(tt,{onClick:()=>s(c.id),active:c.id===g?.id,children:c.name},c.id)),M(Rt,{}),M(tt,{onSelect:c=>{c.preventDefault(),u(!1),d(!0)},children:V("span",{className:"flex items-center gap-1 mx-auto",children:[M(qo,{size:18})," Create new organization"]})})]})]}),M(Wo,{...e,open:m,onOpenChange:d,onSuccess:c=>{u(!1),d(!1),s(c.id),n()}})]})]})})}function Wo(e){let[t,o]=kt(!1),n=e.open!==void 0,r=n?e.open:t,{trigger:i,beforeMutate:a,onSuccess:s,onError:l,auth:u,init:m,baseUrl:d,basePath:g}=e,c=B(e.client),p=gi({defaultValues:{name:""}}),y=di({mutationFn:async b=>{let E={...b,name:b.name.trim()},P=(a&&a(E))??E,I=await Se(e?.fetchUrl??"/tenants",{method:"POST",body:JSON.stringify(P)},{auth:u,init:m,baseUrl:d,basePath:g,fetchUrl:e.fetchUrl});if(!I.ok){let N=await I.text().catch(()=>"");throw new Error(N||"Failed to create organization")}return I.json()},onSuccess:async b=>{p.reset({name:""}),n||o(!1),e.onOpenChange?.(!1),s?.(b)},onError:l},c),S=Qo(b=>{n||o(b),e.onOpenChange?.(b),b||(p.reset({name:""}),y.reset())},[p,n,y,e]),C=Qo(b=>{y.mutate(b)},[y]);return V(Oo,{open:r,onOpenChange:S,children:[i?M(Ao,{asChild:!0,children:i}):null,V(Ft,{children:[V(Dt,{children:[M(Et,{children:"Create an organization"}),M(It,{children:"An organization is a group of users."})]}),M(q,{...p,children:V("form",{onSubmit:p.handleSubmit(C),children:[M(me,{control:p.control,name:"name",rules:{validate:b=>b.trim().length>0||"Organization name is required."},render:({field:b})=>V(ne,{children:[M(re,{children:"Name"}),M(ie,{children:M(Q,{placeholder:"Organization name",...b,autoFocus:!0})}),M(de,{children:"This is the name of your organization."}),M(fe,{})]})}),y.error?M("p",{role:"alert",className:"text-sm text-destructive py-1",children:y.error instanceof Error?y.error.message:"Failed to create organization"}):null,M(R,{type:"submit",className:"py-2",loading:y.isPending,children:"Submit"})]})})]})]})}import{BadgeCheck as Ko,CalendarCheck as bi,CircleUserRound as vi,Mail as wi}from"lucide-react";import Si,{useMemo as Pi}from"react";import{useQuery as yi}from"@tanstack/react-query";function nt(e){let{baseUrl:t="",basePath:o,fetchUrl:n,client:r,user:i,auth:a,init:s}=e??{},l=B(r),{data:u,isLoading:m}=yi({queryKey:["me",t,o,n],queryFn:async()=>{let d=await Se(n??"/me",void 0,{auth:a,init:s,baseUrl:t,basePath:o,fetchUrl:n});if(!d.ok)throw new Error(`Failed to fetch user (${d.status})`);return await d.json()},enabled:i==null},l);return i||u?i??u??null:a&&!(i&&m)?a.state?.session?.user??u??null:null}import{jsx as W,jsxs as we}from"react/jsx-runtime";function Go(e){return W(U,{client:e.client,children:W(xi,{...e})})}function Ci(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{dateStyle:"medium",timeStyle:"short",timeZone:"UTC"}).format(t)}function xi(e){let t=nt(e),o=Si.useMemo(()=>t&&typeof t=="object"&&"picture"in t&&t.picture?W("img",{src:t.picture,alt:`${t.name??t.email} profile picture`,referrerPolicy:"no-referrer"}):e.profilePicturePlaceholder?e.profilePicturePlaceholder:W("div",{className:"drop-shadow-md",style:{background:"linear-gradient(90deg, #F4C587, #D6D3E9, #99D2EC)"},children:W(vi,{size:100,className:"opacity-70 stroke-black",style:{strokeWidth:".5px"}})}),[t,e.profilePicturePlaceholder]),n=Pi(()=>{if(t?.name)return t?.name;let r="";return t?.givenName&&(r=t?.givenName),t?.familyName&&(r=`${r} ${t?.familyName}`),r},[t?.familyName,t?.givenName,t?.name]);return t?we("div",{className:f(e.className,"flex flex-col gap-2 items-center"),children:[we("div",{className:"flex flex-col gap-5 pb-2 items-center",children:[W("div",{className:"flex flex-col gap-2 items-center w-36 mx-auto",children:W("div",{className:"rounded-full border border-background overflow-hidden shadow-md",children:o})}),W("div",{className:"font-bold flex flex-row gap-1 capitalize",children:n})]}),we("div",{className:"flex flex-row gap-5 justify-between w-full",children:[we("div",{className:"flex flex-row gap-2 text-sm items-center w-36",children:[W(wi,{size:14}),"Email:"]}),we("div",{className:"flex flex-row gap-1 items-center",children:[t.emailVerified?W(Ko,{className:"stroke-white fill-green-700",size:14}):W(Ko,{className:"opacity-40",size:14}),t.email," "]})]}),t.created?we("div",{className:"flex flex-row gap-5 justify-between w-full",children:[we("div",{className:"flex flex-row gap-2 text-sm items-center w-36",children:[W(bi,{size:14}),"Created:"]}),Ci(t.created)]}):null]}):"Loading..."}import{useForm as Ni}from"react-hook-form";import{useMutation as _o}from"@tanstack/react-query";import{resetPassword as Ri,forgotPassword as Mi}from"@niledatabase/client";function ze(e){let{auth:t,baseUrl:o="",beforeMutate:n,client:r,callbackUrl:i,fetchUrl:a,init:s,onError:l,onSuccess:u,redirect:m=!1}=e??{},d=B(r),g=_o({mutationFn:async c=>{let y=(n&&n(c))??c;return await Ri({auth:t,baseUrl:o,callbackUrl:i,fetchUrl:a,init:s,redirect:m,...y})},onSuccess:c=>{u?.(c)},onError:l},d);return Ve(e),g}function Xo(e){return ze(e).mutate}function Yo(e){let{auth:t,baseUrl:o="",beforeMutate:n,callbackUrl:r,fetchUrl:i,init:a,client:s,onError:l,onSuccess:u,redirect:m=!1}=e??{},d=B(s),g=_o({mutationFn:async c=>{let y=(n&&n(c))??c;return await Mi({auth:t,baseUrl:o,callbackUrl:r,fetchUrl:i,init:a,redirect:m,...y})},onSuccess:c=>{u?.(c)},onError:l},d);return Ve(e),g}import{jsx as Re,jsxs as Di}from"react/jsx-runtime";function Bt(e){return Re(U,{client:e.client,children:Re(Fi,{...e})})}function Fi(e){let{defaultValues:t,buttonText:o="Reset password",...n}=e,r=Ni({defaultValues:{email:"",...t}}),i=ze({...n,redirect:!0});return Re(q,{...r,children:Di("form",{className:"py-2",onSubmit:r.handleSubmit(({email:a})=>{i.mutate({email:a})}),children:[Re(J,{}),!e.onError&&i.error?Re("p",{role:"alert",className:"text-sm font-medium text-destructive",children:i.error instanceof Error?i.error.message:"Password reset request failed"}):null,Re(R,{type:"submit",loading:i.isPending,children:o})]})})}import{jsx as Zo,jsxs as Ei}from"react/jsx-runtime";function Lt(e){return Ei("div",{className:"flex flex-col gap-4",children:[Zo("h2",{className:"font-sans text-3xl",children:"Request password reset"}),Zo(Bt,{...e})]})}import{useForm as Ii}from"react-hook-form";import{useEffect as ki,useState as Bi}from"react";import{jsx as O,jsxs as Tt}from"react/jsx-runtime";function Ut(e){return O(U,{client:e.client,children:O(Li,{...e})})}function Li(e){let{defaultValues:t,mode:o,buttonText:n="Update password",...r}=e,i=Ii({defaultValues:{email:"",password:"",confirmPassword:"",...t}}),a=Yo(r),s=ze(r),l=i.watch("password"),u=i.watch("confirmPassword"),[m,d]=Bi(!0),g=a.isPending||s.isPending,c=a.error||s.error;return ki(()=>{i.clearErrors(),!l||!u?d(!0):l!==u?(i.setError("confirmPassword",{message:"Passwords must match."}),d(!0)):d(!1)},[l,u,i]),O(q,{...i,children:Tt("form",{onSubmit:i.handleSubmit(({email:p,password:y})=>{o==="forgot"||!o&&!p?a.mutate({password:y}):s.mutate({email:p,password:y})}),className:"py-2",children:[t?.email?O(me,{control:i.control,name:"email",render:({field:p})=>Tt(ne,{children:[O(re,{children:"Email address"}),O(ie,{children:O(Q,{...p,disabled:!0})})]})}):null,O(pe,{autoComplete:"new-password"}),O(me,{control:i.control,name:"confirmPassword",render:({field:p})=>Tt(ne,{children:[O(re,{children:"Confirm password"}),O(ie,{children:O(Q,{placeholder:"Password",...p,type:"password",autoComplete:"new-password"})}),O(de,{children:"Confirm your new password"}),O(fe,{})]})}),!e.onError&&c?O("p",{role:"alert",className:"text-sm font-medium text-destructive",children:c instanceof Error?c.message:"Password update failed"}):null,O(R,{type:"submit",loading:g,disabled:Object.keys(i.formState.errors).length>0||m,children:n})]})})}import{jsx as rt,jsxs as Ui}from"react/jsx-runtime";function zt(e){return rt(U,{client:e.client,children:rt(Ti,{...e})})}function Ti({className:e,...t}){return Ui("div",{className:f(e,"flex flex-col gap-4"),children:[rt("h2",{className:"font-sans text-3xl",children:"Reset password"}),rt(Ut,{...t})]})}import{getSession as Im,getCsrfToken as km,getProviders as Bm,signIn as Lm,signOut as Tm,auth as Um,Authorizer as zm}from"@niledatabase/client";export{zm as Authorizer,Un as Azure,An as Discord,J as Email,ut as EmailSignIn,eo as EmailSignInButton,Vn as GitHub,oo as Google,qn as HubSpot,$n as LinkedIn,ko as MultiFactorAuthenticator,Uo as MultiFactorChallenge,Lo as MultiFactorEmail,le as MultiFactorVerify,jn as Okta,pe as Password,zt as PasswordResetForm,Lt as PasswordResetRequestForm,De as SessionContext,Ie as SessionProvider,pt as SignInForm,br as SignOutButton,dt as SignUpForm,wo as SignedIn,So as SignedOut,_n as Slack,$o as TenantSelector,Go as UserInfo,Zn as X,Um as auth,xe as clearMfaChallenge,km as getCsrfToken,Bm as getProviders,Im as getSession,Je as readMfaChallenge,Lm as signIn,Tm as signOut,Ze as storeMfaChallenge,Yt as useEmailSignIn,nt as useMe,Do as useMultiFactor,Xo as useResetPassword,Ee as useSession,_e as useSignIn,Ge as useSignUp,ot as useTenantId,Ue as useTenants};
|
|
31
31
|
//# sourceMappingURL=index.mjs.map
|