@supertokens/rownd-react 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/components/RequireSignIn.d.ts +11 -0
- package/dist/components/RequireSignIn.js +18 -0
- package/dist/components/RequireSignIn.js.map +1 -0
- package/dist/components/SignedIn.d.ts +7 -0
- package/dist/components/SignedIn.js +11 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/SignedOut.d.ts +7 -0
- package/dist/components/SignedOut.js +11 -0
- package/dist/components/SignedOut.js.map +1 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.d.ts +17 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.js +34 -0
- package/dist/context/HubScriptInjector/HubScriptInjector.js.map +1 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.d.ts +3 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.js +19 -0
- package/dist/context/HubScriptInjector/InternalProviderHubScriptInjector.js.map +1 -0
- package/dist/context/InternalProvider.d.ts +9 -0
- package/dist/context/InternalProvider.js +13 -0
- package/dist/context/InternalProvider.js.map +1 -0
- package/dist/context/ReactRowndProvider.d.ts +4 -0
- package/dist/context/ReactRowndProvider.js +43 -0
- package/dist/context/ReactRowndProvider.js.map +1 -0
- package/dist/context/RowndContext.d.ts +33 -0
- package/dist/context/RowndContext.js +13 -0
- package/dist/context/RowndContext.js.map +1 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/types.d.ts +112 -0
- package/dist/hooks/useHub.d.ts +48 -0
- package/dist/hooks/useHub.js +153 -0
- package/dist/hooks/useHub.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +13 -0
- package/dist/main.js.map +1 -0
- package/dist/next/RowndProvider.d.ts +5 -0
- package/dist/next/RowndProvider.js +9 -0
- package/dist/next/RowndProvider.js.map +1 -0
- package/dist/next/client/components/RequireSignIn.d.ts +5 -0
- package/dist/next/client/components/RequireSignIn.js +30 -0
- package/dist/next/client/components/RequireSignIn.js.map +1 -0
- package/dist/next/client/components/RowndServerStateSync.d.ts +2 -0
- package/dist/next/client/components/RowndServerStateSync.js +36 -0
- package/dist/next/client/components/RowndServerStateSync.js.map +1 -0
- package/dist/next/client/components/RowndServerStateSync.test.d.ts +1 -0
- package/dist/next/client/index.d.ts +5 -0
- package/dist/next/client/index.js +49 -0
- package/dist/next/client/index.js.map +1 -0
- package/dist/next/client/store/index.d.ts +3 -0
- package/dist/next/client/store/index.js +52 -0
- package/dist/next/client/store/index.js.map +1 -0
- package/dist/next/client/store/store.d.ts +13 -0
- package/dist/next/client/store/store.js +32 -0
- package/dist/next/client/store/store.js.map +1 -0
- package/dist/next/client/store/useStore.d.ts +3 -0
- package/dist/next/client/store/useStore.js +14 -0
- package/dist/next/client/store/useStore.js.map +1 -0
- package/dist/next/client/useRownd.d.ts +3 -0
- package/dist/next/client/useRownd.js +32 -0
- package/dist/next/client/useRownd.js.map +1 -0
- package/dist/next/client/withRowndRequireSignIn.d.ts +8 -0
- package/dist/next/client/withRowndRequireSignIn.js +19 -0
- package/dist/next/client/withRowndRequireSignIn.js.map +1 -0
- package/dist/next/index.d.ts +6 -0
- package/dist/next/server/getRowndAccessToken.d.ts +3 -0
- package/dist/next/server/getRowndAccessToken.js +11 -0
- package/dist/next/server/getRowndAccessToken.js.map +1 -0
- package/dist/next/server/getRowndUser.d.ts +11 -0
- package/dist/next/server/getRowndUser.js +11 -0
- package/dist/next/server/getRowndUser.js.map +1 -0
- package/dist/next/server/getRowndUserId.d.ts +3 -0
- package/dist/next/server/getRowndUserId.js +11 -0
- package/dist/next/server/getRowndUserId.js.map +1 -0
- package/dist/next/server/index.d.ts +8 -0
- package/dist/next/server/isAuthenticated.d.ts +3 -0
- package/dist/next/server/isAuthenticated.js +11 -0
- package/dist/next/server/isAuthenticated.js.map +1 -0
- package/dist/next/server/withRowndMiddleware.d.ts +4 -0
- package/dist/next/server/withRowndMiddleware.js +11 -0
- package/dist/next/server/withRowndMiddleware.js.map +1 -0
- package/dist/next/useRownd.d.ts +3 -0
- package/dist/next-server.d.ts +1 -0
- package/dist/next-server.js +15 -0
- package/dist/next-server.js.map +1 -0
- package/dist/next.d.ts +1 -0
- package/dist/next.js +11 -0
- package/dist/next.js.map +1 -0
- package/dist/remix/RemixRowndProvider.d.ts +5 -0
- package/dist/remix/RemixRowndProvider.js +28 -0
- package/dist/remix/RemixRowndProvider.js.map +1 -0
- package/dist/remix/client/RemixClientScript.d.ts +4 -0
- package/dist/remix/client/RemixClientScript.js +22 -0
- package/dist/remix/client/RemixClientScript.js.map +1 -0
- package/dist/remix/client/useRownd.d.ts +4 -0
- package/dist/remix/client/useRownd.js +35 -0
- package/dist/remix/client/useRownd.js.map +1 -0
- package/dist/remix/client/withRowndRequireSignIn.d.ts +4 -0
- package/dist/remix/client/withRowndRequireSignIn.js +27 -0
- package/dist/remix/client/withRowndRequireSignIn.js.map +1 -0
- package/dist/remix/index.d.ts +7 -0
- package/dist/remix/server/getRowndUser.d.ts +3 -0
- package/dist/remix/server/getRowndUser.js +11 -0
- package/dist/remix/server/getRowndUser.js.map +1 -0
- package/dist/remix/server/getRowndUserId.d.ts +1 -0
- package/dist/remix/server/getRowndUserId.js +8 -0
- package/dist/remix/server/getRowndUserId.js.map +1 -0
- package/dist/remix/server/index.d.ts +8 -0
- package/dist/remix/server/isAuthenticated.d.ts +1 -0
- package/dist/remix/server/isAuthenticated.js +8 -0
- package/dist/remix/server/isAuthenticated.js.map +1 -0
- package/dist/remix/server/withRowndActionHandler.d.ts +2 -0
- package/dist/remix/server/withRowndActionHandler.js +41 -0
- package/dist/remix/server/withRowndActionHandler.js.map +1 -0
- package/dist/remix/server/withRowndLoader.d.ts +13 -0
- package/dist/remix/server/withRowndLoader.js +19 -0
- package/dist/remix/server/withRowndLoader.js.map +1 -0
- package/dist/remix-server.d.ts +1 -0
- package/dist/remix-server.js +15 -0
- package/dist/remix-server.js.map +1 -0
- package/dist/remix.d.ts +1 -0
- package/dist/remix.js +17 -0
- package/dist/remix.js.map +1 -0
- package/dist/ssr/hooks/useCookie.d.ts +7 -0
- package/dist/ssr/hooks/useCookie.js +22 -0
- package/dist/ssr/hooks/useCookie.js.map +1 -0
- package/dist/ssr/server/cookie.d.ts +13 -0
- package/dist/ssr/server/cookie.js +51 -0
- package/dist/ssr/server/cookie.js.map +1 -0
- package/dist/ssr/server/token.d.ts +44 -0
- package/dist/ssr/server/token.js +128 -0
- package/dist/ssr/server/token.js.map +1 -0
- package/dist/ssr/server/token.test.d.ts +1 -0
- package/dist/utils/listeners.d.ts +8 -0
- package/dist/utils/listeners.js +15 -0
- package/dist/utils/listeners.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class i {
|
|
2
|
+
constructor(t) {
|
|
3
|
+
this.state = t, this.listeners = /* @__PURE__ */ new Set();
|
|
4
|
+
}
|
|
5
|
+
getState() {
|
|
6
|
+
return this.state;
|
|
7
|
+
}
|
|
8
|
+
setState(t) {
|
|
9
|
+
const s = typeof t == "function" ? t(this.state) : t;
|
|
10
|
+
this.state = { ...this.state, ...s }, this.notify();
|
|
11
|
+
}
|
|
12
|
+
subscribe(t) {
|
|
13
|
+
return this.listeners.add(t), () => {
|
|
14
|
+
this.listeners.delete(t);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
notify() {
|
|
18
|
+
this.listeners.forEach((t) => t(this.state));
|
|
19
|
+
}
|
|
20
|
+
// Selector support for optimized re-renders
|
|
21
|
+
select(t) {
|
|
22
|
+
return t(this.state);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function n(e) {
|
|
26
|
+
return new i(e);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Store,
|
|
30
|
+
n as createStore
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../../../../src/next/client/store/store.ts"],"sourcesContent":["export type Listener<T> = (state: T) => void;\nexport type Selector<T, U> = (state: T) => U;\n\nexport class Store<T extends object> {\n private state: T;\n private listeners: Set<Listener<T>>;\n\n constructor(initialState: T) {\n this.state = initialState;\n this.listeners = new Set();\n }\n\n getState(): T {\n return this.state;\n }\n\n setState(partial: Partial<T> | ((state: T) => Partial<T>)): void {\n const nextState =\n typeof partial === 'function' ? partial(this.state) : partial;\n\n this.state = { ...this.state, ...nextState };\n this.notify();\n }\n\n subscribe(listener: Listener<T>): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n private notify(): void {\n this.listeners.forEach((listener) => listener(this.state));\n }\n\n // Selector support for optimized re-renders\n select<U>(selector: Selector<T, U>): U {\n return selector(this.state);\n }\n}\n\n// Helper function to create a store\nexport function createStore<T extends object>(initialState: T): Store<T> {\n return new Store(initialState);\n}\n"],"names":["Store","initialState","partial","nextState","listener","selector","createStore"],"mappings":"AAGO,MAAMA,EAAwB;AAAA,EAInC,YAAYC,GAAiB;AAC3B,SAAK,QAAQA,GACb,KAAK,gCAAgB,IAAA;AAAA,EACvB;AAAA,EAEA,WAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAASC,GAAwD;AAC/D,UAAMC,IACJ,OAAOD,KAAY,aAAaA,EAAQ,KAAK,KAAK,IAAIA;AAExD,SAAK,QAAQ,EAAE,GAAG,KAAK,OAAO,GAAGC,EAAA,GACjC,KAAK,OAAA;AAAA,EACP;AAAA,EAEA,UAAUC,GAAmC;AAC3C,gBAAK,UAAU,IAAIA,CAAQ,GACpB,MAAM;AACX,WAAK,UAAU,OAAOA,CAAQ;AAAA,IAChC;AAAA,EACF;AAAA,EAEQ,SAAe;AACrB,SAAK,UAAU,QAAQ,CAACA,MAAaA,EAAS,KAAK,KAAK,CAAC;AAAA,EAC3D;AAAA;AAAA,EAGA,OAAUC,GAA6B;AACrC,WAAOA,EAAS,KAAK,KAAK;AAAA,EAC5B;AACF;AAGO,SAASC,EAA8BL,GAA2B;AACvE,SAAO,IAAID,EAAMC,CAAY;AAC/B;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as i, useEffect as a } from "react";
|
|
3
|
+
function S(u, t) {
|
|
4
|
+
const [n, f] = i(
|
|
5
|
+
() => t ? u.select(t) : u.getState()
|
|
6
|
+
);
|
|
7
|
+
return a(() => u.subscribe((e) => {
|
|
8
|
+
f(t ? t(e) : e);
|
|
9
|
+
}), [u, t]), n;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
S as useStore
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStore.js","sources":["../../../../src/next/client/store/useStore.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\nimport { Store, Selector } from './store';\n\nexport function useStore<T extends object, U>(\n store: Store<T>,\n selector?: Selector<T, U>\n) {\n const [state, setState] = useState(() => \n selector ? store.select(selector) : store.getState()\n );\n\n useEffect(() => {\n return store.subscribe((newState) => {\n setState(selector ? selector(newState) : newState);\n });\n }, [store, selector]);\n\n return state;\n}"],"names":["useStore","store","selector","state","setState","useState","useEffect","newState"],"mappings":";;AAKO,SAASA,EACdC,GACAC,GACA;AACA,QAAM,CAACC,GAAOC,CAAQ,IAAIC;AAAA,IAAS,MACjCH,IAAWD,EAAM,OAAOC,CAAQ,IAAID,EAAM,SAAA;AAAA,EAAS;AAGrD,SAAAK,EAAU,MACDL,EAAM,UAAU,CAACM,MAAa;AACnC,IAAAH,EAASF,IAAWA,EAASK,CAAQ,IAAIA,CAAQ;AAAA,EACnD,CAAC,GACA,CAACN,GAAOC,CAAQ,CAAC,GAEbC;AACT;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useStore as r } from "./store/useStore.js";
|
|
2
|
+
import { store as s } from "./store/index.js";
|
|
3
|
+
import { useCallback as i, useMemo as u } from "react";
|
|
4
|
+
import { setCookie as c } from "../../ssr/server/cookie.js";
|
|
5
|
+
import { addOnAuthenticatedListener as m, unsubscribeOnAuthenticatedListener as a } from "../../utils/listeners.js";
|
|
6
|
+
const O = () => {
|
|
7
|
+
const e = r(s, (t) => t), o = i(
|
|
8
|
+
(t) => {
|
|
9
|
+
const n = m(t);
|
|
10
|
+
return () => {
|
|
11
|
+
a(n);
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
16
|
+
return u(() => ({
|
|
17
|
+
...e,
|
|
18
|
+
onAuthenticated: o,
|
|
19
|
+
signOut: async () => {
|
|
20
|
+
try {
|
|
21
|
+
await c("invalid");
|
|
22
|
+
} catch (t) {
|
|
23
|
+
console.log("Failed to set sign out cookie: ", t);
|
|
24
|
+
}
|
|
25
|
+
e.signOut();
|
|
26
|
+
}
|
|
27
|
+
}), [e]);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
O as useRownd
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=useRownd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRownd.js","sources":["../../../src/next/client/useRownd.tsx"],"sourcesContent":["import { useStore } from './store/useStore';\nimport { store } from './store';\nimport { TRowndContext, UserDataContext } from '../../context/types';\nimport { useCallback, useMemo } from 'react';\nimport { setCookie } from '../../ssr/server/cookie';\nimport { addOnAuthenticatedListener, unsubscribeOnAuthenticatedListener } from '../../utils/listeners';\n\nexport const useRownd = (): TRowndContext => {\n const state = useStore(store, (x) => x);\n\n const onAuthenticated: (\n callback: (userData: UserDataContext) => void\n ) => () => void = useCallback(\n (callback: (userData: UserDataContext) => void) => {\n const id = addOnAuthenticatedListener(callback);\n\n const unsubscribe = () => {\n unsubscribeOnAuthenticatedListener(id);\n };\n\n return unsubscribe;\n },\n []\n );\n\n const memoized = useMemo(() => {\n return {\n ...state,\n onAuthenticated,\n signOut: async () => {\n try {\n await setCookie('invalid');\n } catch (err) {\n console.log('Failed to set sign out cookie: ', err);\n }\n state.signOut();\n },\n };\n }, [state]);\n\n return memoized;\n};\n"],"names":["useRownd","state","useStore","store","x","onAuthenticated","useCallback","callback","id","addOnAuthenticatedListener","unsubscribeOnAuthenticatedListener","useMemo","setCookie","err"],"mappings":";;;;;AAOO,MAAMA,IAAW,MAAqB;AAC3C,QAAMC,IAAQC,EAASC,GAAO,CAACC,MAAMA,CAAC,GAEhCC,IAEYC;AAAA,IAChB,CAACC,MAAkD;AACjD,YAAMC,IAAKC,EAA2BF,CAAQ;AAM9C,aAJoB,MAAM;AACxB,QAAAG,EAAmCF,CAAE;AAAA,MACvC;AAAA,IAGF;AAAA,IACA,CAAA;AAAA,EAAC;AAkBH,SAfiBG,EAAQ,OAChB;AAAA,IACL,GAAGV;AAAA,IACH,iBAAAI;AAAA,IACA,SAAS,YAAY;AACnB,UAAI;AACF,cAAMO,EAAU,SAAS;AAAA,MAC3B,SAASC,GAAK;AACZ,gBAAQ,IAAI,mCAAmCA,CAAG;AAAA,MACpD;AACA,MAAAZ,EAAM,QAAA;AAAA,IACR;AAAA,EAAA,IAED,CAACA,CAAK,CAAC;AAGZ;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { RequestCookiesFn } from '../server/getRowndUser';
|
|
3
|
+
|
|
4
|
+
type ReactServerComponent<Props> = (props: Props) => React.ReactNode;
|
|
5
|
+
declare const withRowndRequireSignIn: <P extends object>(WrappedComponent: ReactServerComponent<P>, cookies: RequestCookiesFn, Fallback: React.ComponentType, options: {
|
|
6
|
+
onUnauthenticated?: () => void;
|
|
7
|
+
} | undefined) => (props: P) => Promise<React.JSX.Element>;
|
|
8
|
+
export default withRowndRequireSignIn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import e from "react";
|
|
2
|
+
import { getRowndAuthenticationStatus as d } from "../../ssr/server/token.js";
|
|
3
|
+
import { ROWND_COOKIE_ID as f } from "../../ssr/server/cookie.js";
|
|
4
|
+
import r from "./components/RequireSignIn.js";
|
|
5
|
+
const R = (c, i, l, t) => async (u) => {
|
|
6
|
+
var a;
|
|
7
|
+
const o = ((a = (await i()).get(f)) == null ? void 0 : a.value) ?? null, n = await d(o);
|
|
8
|
+
if (!n.is_authenticated)
|
|
9
|
+
return t != null && t.onUnauthenticated && !n.is_expired && t.onUnauthenticated(), /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(r, { isFallback: !0 }), /* @__PURE__ */ e.createElement(l, null));
|
|
10
|
+
const s = {
|
|
11
|
+
access_token: n.access_token,
|
|
12
|
+
user_id: n.user_id
|
|
13
|
+
}, m = c;
|
|
14
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(m, { ...u, user: s }), /* @__PURE__ */ e.createElement(r, { isFallback: !1 }));
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
R as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=withRowndRequireSignIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withRowndRequireSignIn.js","sources":["../../../src/next/client/withRowndRequireSignIn.tsx"],"sourcesContent":["import React from 'react';\nimport { getRowndAuthenticationStatus, RowndAuthenticatedUser } from '../../ssr/server/token';\nimport { ROWND_COOKIE_ID } from '../../ssr/server/cookie';\nimport RequireSignIn from './components/RequireSignIn';\nimport { RequestCookiesFn } from '../server/getRowndUser';\n\ntype ReactServerComponent<Props> = (props: Props) => React.ReactNode;\n\nconst withRowndRequireSignIn = <P extends object>(\n WrappedComponent: ReactServerComponent<P>,\n cookies: RequestCookiesFn,\n Fallback: React.ComponentType,\n options: {\n onUnauthenticated?: () => void;\n } | undefined\n) => {\n return async (props: P) => {\n const cookieObj = await cookies();\n const rowndToken = cookieObj.get(ROWND_COOKIE_ID)?.value ?? null;\n const status = await getRowndAuthenticationStatus(rowndToken);\n\n if (!status.is_authenticated) {\n if (options?.onUnauthenticated && !status.is_expired) {\n options.onUnauthenticated();\n }\n return (\n <>\n <RequireSignIn isFallback={true} />\n <Fallback />\n </>\n );\n }\n\n const user: RowndAuthenticatedUser = {\n access_token: status.access_token,\n user_id: status.user_id,\n };\n\n const Component = WrappedComponent as unknown as React.ComponentType<P>;\n return (\n <>\n <Component {...props} user={user} />\n <RequireSignIn isFallback={false} />\n </>\n );\n };\n};\n\nexport default withRowndRequireSignIn;\n"],"names":["withRowndRequireSignIn","WrappedComponent","cookies","Fallback","options","props","rowndToken","_a","ROWND_COOKIE_ID","status","getRowndAuthenticationStatus","React","RequireSignIn","user","Component"],"mappings":";;;;AAQA,MAAMA,IAAyB,CAC7BC,GACAC,GACAC,GACAC,MAIO,OAAOC,MAAa;;AAEzB,QAAMC,MAAaC,KADD,MAAML,EAAA,GACK,IAAIM,CAAe,MAA7B,gBAAAD,EAAgC,UAAS,MACtDE,IAAS,MAAMC,EAA6BJ,CAAU;AAE5D,MAAI,CAACG,EAAO;AACV,WAAIL,KAAA,QAAAA,EAAS,qBAAqB,CAACK,EAAO,cACxCL,EAAQ,kBAAA,GAGR,gBAAAO,EAAA,cAAAA,EAAA,UAAA,sCACGC,GAAA,EAAc,YAAY,IAAM,GACjC,gBAAAD,EAAA,cAACR,OAAS,CACZ;AAIJ,QAAMU,IAA+B;AAAA,IACjC,cAAcJ,EAAO;AAAA,IACrB,SAASA,EAAO;AAAA,EAAA,GAGdK,IAAYb;AAClB,SACE,gBAAAU,EAAA,cAAAA,EAAA,UAAA,MACE,gBAAAA,EAAA,cAACG,GAAA,EAAW,GAAGT,GAAO,MAAAQ,EAAA,CAAY,GAClC,gBAAAF,EAAA,cAACC,GAAA,EAAc,YAAY,GAAA,CAAO,CACpC;AAEJ;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RowndProvider } from './RowndProvider';
|
|
2
|
+
import { useRownd } from './client/useRownd';
|
|
3
|
+
import { default as withRowndRequireSignIn } from './client/withRowndRequireSignIn';
|
|
4
|
+
import { default as RowndServerStateSync } from './client/components/RowndServerStateSync';
|
|
5
|
+
|
|
6
|
+
export { RowndProvider, useRownd, withRowndRequireSignIn, RowndServerStateSync };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus as e } from "../../ssr/server/token.js";
|
|
2
|
+
import { ROWND_COOKIE_ID as s } from "../../ssr/server/cookie.js";
|
|
3
|
+
const u = async (o) => {
|
|
4
|
+
var t;
|
|
5
|
+
const n = ((t = (await o()).get(s)) == null ? void 0 : t.value) ?? null;
|
|
6
|
+
return (await e(n)).access_token ?? null;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
u as getRowndAccessToken
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getRowndAccessToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRowndAccessToken.js","sources":["../../../src/next/server/getRowndAccessToken.ts"],"sourcesContent":["import {\n getRowndAuthenticationStatus,\n} from '../../ssr/server/token';\nimport { ROWND_COOKIE_ID } from '../../ssr/server/cookie';\nimport { RequestCookiesFn } from './getRowndUser';\n\nexport const getRowndAccessToken = async (\n cookies: RequestCookiesFn\n): Promise<string | null> => {\n const cookieObj = await cookies();\n const rowndToken = cookieObj.get(ROWND_COOKIE_ID)?.value ?? null;\n const status = await getRowndAuthenticationStatus(rowndToken);\n\n return status.access_token ?? null;\n};\n"],"names":["getRowndAccessToken","cookies","rowndToken","_a","ROWND_COOKIE_ID","getRowndAuthenticationStatus"],"mappings":";;AAMO,MAAMA,IAAsB,OACjCC,MAC2B;;AAE3B,QAAMC,MAAaC,KADD,MAAMF,EAAA,GACK,IAAIG,CAAe,MAA7B,gBAAAD,EAAgC,UAAS;AAG5D,UAFe,MAAME,EAA6BH,CAAU,GAE9C,gBAAgB;AAChC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UserContext } from '../../context/types';
|
|
2
|
+
|
|
3
|
+
export type RequestCookiesFn = () => Promise<ReadOnlyRequestCookies> | ReadOnlyRequestCookies;
|
|
4
|
+
export type ReadOnlyRequestCookies = {
|
|
5
|
+
get: (name: string) => RequestCookie | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type RequestCookie = {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const getRowndUser: (cookies: RequestCookiesFn) => Promise<UserContext | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus as n, getRowndUserData as s } from "../../ssr/server/token.js";
|
|
2
|
+
import { ROWND_COOKIE_ID as r } from "../../ssr/server/cookie.js";
|
|
3
|
+
const w = async (e) => {
|
|
4
|
+
var o;
|
|
5
|
+
const a = ((o = (await e()).get(r)) == null ? void 0 : o.value) ?? null, t = await n(a, { allowExpired: !1 });
|
|
6
|
+
return t.access_token ? await s(t.access_token) : null;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
w as getRowndUser
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getRowndUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRowndUser.js","sources":["../../../src/next/server/getRowndUser.ts"],"sourcesContent":["import {\n getRowndAuthenticationStatus,\n getRowndUserData,\n} from '../../ssr/server/token';\nimport { ROWND_COOKIE_ID } from '../../ssr/server/cookie';\nimport { UserContext } from '../../context/types';\n\nexport type RequestCookiesFn =\n () => Promise<ReadOnlyRequestCookies> | ReadOnlyRequestCookies;\n\nexport type ReadOnlyRequestCookies = {\n get: (name: string) => RequestCookie | undefined;\n};\n\nexport type RequestCookie = {\n name: string;\n value: string;\n};\n\nexport const getRowndUser =\n async (cookies: RequestCookiesFn): Promise<UserContext | null> => {\n const cookieObj = await cookies();\n const rowndToken = cookieObj.get(ROWND_COOKIE_ID)?.value ?? null;\n const status = await getRowndAuthenticationStatus(rowndToken, { allowExpired: false });\n\n if (!status.access_token) {\n return null;\n }\n\n const userData = await getRowndUserData(status.access_token);\n return userData;\n };\n"],"names":["getRowndUser","cookies","rowndToken","_a","ROWND_COOKIE_ID","status","getRowndAuthenticationStatus","getRowndUserData"],"mappings":";;AAmBO,MAAMA,IACX,OAAOC,MAA2D;;AAEhE,QAAMC,MAAaC,KADD,MAAMF,EAAA,GACK,IAAIG,CAAe,MAA7B,gBAAAD,EAAgC,UAAS,MACtDE,IAAS,MAAMC,EAA6BJ,GAAY,EAAE,cAAc,IAAO;AAErF,SAAKG,EAAO,eAIK,MAAME,EAAiBF,EAAO,YAAY,IAHlD;AAKX;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus as e } from "../../ssr/server/token.js";
|
|
2
|
+
import { ROWND_COOKIE_ID as s } from "../../ssr/server/cookie.js";
|
|
3
|
+
const c = async (o) => {
|
|
4
|
+
var t;
|
|
5
|
+
const n = ((t = (await o()).get(s)) == null ? void 0 : t.value) ?? null;
|
|
6
|
+
return (await e(n)).user_id ?? null;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
c as getRowndUserId
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getRowndUserId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRowndUserId.js","sources":["../../../src/next/server/getRowndUserId.ts"],"sourcesContent":["import { getRowndAuthenticationStatus } from '../../ssr/server/token';\nimport { ROWND_COOKIE_ID } from '../../ssr/server/cookie';\nimport { RequestCookiesFn } from './getRowndUser';\n\nexport const getRowndUserId = async (\n cookies: RequestCookiesFn\n): Promise<string | null> => {\n const cookieObj = await cookies();\n const rowndToken = cookieObj.get(ROWND_COOKIE_ID)?.value ?? null;\n const status = await getRowndAuthenticationStatus(rowndToken);\n\n return status.user_id ?? null;\n};\n"],"names":["getRowndUserId","cookies","rowndToken","_a","ROWND_COOKIE_ID","getRowndAuthenticationStatus"],"mappings":";;AAIO,MAAMA,IAAiB,OAC5BC,MAC2B;;AAE3B,QAAMC,MAAaC,KADD,MAAMF,EAAA,GACK,IAAIG,CAAe,MAA7B,gBAAAD,EAAgC,UAAS;AAG5D,UAFe,MAAME,EAA6BH,CAAU,GAE9C,WAAW;AAC3B;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getRowndUser } from './getRowndUser';
|
|
2
|
+
import { withRowndMiddleware } from './withRowndMiddleware';
|
|
3
|
+
import { isAuthenticated } from './isAuthenticated';
|
|
4
|
+
import { ROWND_TOKEN_CALLBACK_PATH } from '../../ssr/server/cookie';
|
|
5
|
+
import { getRowndAccessToken } from './getRowndAccessToken';
|
|
6
|
+
import { getRowndUserId } from './getRowndUserId';
|
|
7
|
+
|
|
8
|
+
export { getRowndUser, withRowndMiddleware, isAuthenticated, ROWND_TOKEN_CALLBACK_PATH, getRowndAccessToken, getRowndUserId, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus as a } from "../../ssr/server/token.js";
|
|
2
|
+
import { ROWND_COOKIE_ID as e } from "../../ssr/server/cookie.js";
|
|
3
|
+
const r = async (o) => {
|
|
4
|
+
var t;
|
|
5
|
+
const n = ((t = (await o()).get(e)) == null ? void 0 : t.value) ?? null;
|
|
6
|
+
return (await a(n)).is_authenticated;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
r as isAuthenticated
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=isAuthenticated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAuthenticated.js","sources":["../../../src/next/server/isAuthenticated.ts"],"sourcesContent":["import { getRowndAuthenticationStatus } from '../../ssr/server/token';\nimport { ROWND_COOKIE_ID } from '../../ssr/server/cookie';\nimport { RequestCookiesFn } from './getRowndUser';\n\nexport const isAuthenticated = async (\n cookies: RequestCookiesFn\n): Promise<boolean> => {\n const cookieObj = await cookies();\n const rowndToken = cookieObj.get(ROWND_COOKIE_ID)?.value ?? null;\n const status = await getRowndAuthenticationStatus(rowndToken);\n\n return status.is_authenticated;\n};\n"],"names":["isAuthenticated","cookies","rowndToken","_a","ROWND_COOKIE_ID","getRowndAuthenticationStatus"],"mappings":";;AAIO,MAAMA,IAAkB,OAC7BC,MACqB;;AAErB,QAAMC,MAAaC,KADD,MAAMF,EAAA,GACK,IAAIG,CAAe,MAA7B,gBAAAD,EAAgC,UAAS;AAG5D,UAFe,MAAME,EAA6BH,CAAU,GAE9C;AAChB;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { handleRowndTokenCallback as l } from "../../remix/server/withRowndActionHandler.js";
|
|
2
|
+
import { ROWND_TOKEN_CALLBACK_PATH as h, ROWND_COOKIE_ID as m } from "../../ssr/server/cookie.js";
|
|
3
|
+
import { getRowndAuthenticationStatus as d } from "../../ssr/server/token.js";
|
|
4
|
+
const R = (i) => (n) => {
|
|
5
|
+
var t, o, a;
|
|
6
|
+
return (o = (t = n == null ? void 0 : n.nextUrl) == null ? void 0 : t.pathname) != null && o.startsWith(h) ? l(n) : d(((a = n.cookies.get(m)) == null ? void 0 : a.value) || null).then((r) => (n.auth = r, i(n)));
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
R as withRowndMiddleware
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=withRowndMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withRowndMiddleware.js","sources":["../../../src/next/server/withRowndMiddleware.ts"],"sourcesContent":["import { handleRowndTokenCallback } from '../../remix/server/withRowndActionHandler';\nimport { ROWND_COOKIE_ID, ROWND_TOKEN_CALLBACK_PATH } from '../../ssr/server/cookie';\nimport { getRowndAuthenticationStatus } from '../../ssr/server/token';\n\ntype NextResponse = any;\ntype NextRequest = any;\n\nexport const withRowndMiddleware = (\n middleware: (request: NextRequest) => NextResponse\n) => {\n return (request: NextRequest) => {\n if (request?.nextUrl?.pathname?.startsWith(ROWND_TOKEN_CALLBACK_PATH)) {\n return handleRowndTokenCallback(request)\n }\n\n return getRowndAuthenticationStatus(request.cookies.get(ROWND_COOKIE_ID)?.value || null).then((tokenInfo) => {\n request.auth = tokenInfo;\n\n return middleware(request);\n });\n };\n};\n"],"names":["withRowndMiddleware","middleware","request","_b","_a","ROWND_TOKEN_CALLBACK_PATH","handleRowndTokenCallback","getRowndAuthenticationStatus","_c","ROWND_COOKIE_ID","tokenInfo"],"mappings":";;;AAOO,MAAMA,IAAsB,CACjCC,MAEO,CAACC,MAAyB;;AAC/B,UAAIC,KAAAC,IAAAF,KAAA,gBAAAA,EAAS,YAAT,gBAAAE,EAAkB,aAAlB,QAAAD,EAA4B,WAAWE,KAClCC,EAAyBJ,CAAO,IAGlCK,IAA6BC,IAAAN,EAAQ,QAAQ,IAAIO,CAAe,MAAnC,gBAAAD,EAAsC,UAAS,IAAI,EAAE,KAAK,CAACE,OAC7FR,EAAQ,OAAOQ,GAERT,EAAWC,CAAO,EAC1B;AACH;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './next/server/index'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getRowndUser as r } from "./next/server/getRowndUser.js";
|
|
2
|
+
import { withRowndMiddleware as d } from "./next/server/withRowndMiddleware.js";
|
|
3
|
+
import { isAuthenticated as m } from "./next/server/isAuthenticated.js";
|
|
4
|
+
import { ROWND_TOKEN_CALLBACK_PATH as p } from "./ssr/server/cookie.js";
|
|
5
|
+
import { getRowndAccessToken as x } from "./next/server/getRowndAccessToken.js";
|
|
6
|
+
import { getRowndUserId as A } from "./next/server/getRowndUserId.js";
|
|
7
|
+
export {
|
|
8
|
+
p as ROWND_TOKEN_CALLBACK_PATH,
|
|
9
|
+
x as getRowndAccessToken,
|
|
10
|
+
r as getRowndUser,
|
|
11
|
+
A as getRowndUserId,
|
|
12
|
+
m as isAuthenticated,
|
|
13
|
+
d as withRowndMiddleware
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=next-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './next/index'
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RowndProvider as r } from "./next/RowndProvider.js";
|
|
2
|
+
import { useRownd as d } from "./next/client/useRownd.js";
|
|
3
|
+
import { default as f } from "./next/client/withRowndRequireSignIn.js";
|
|
4
|
+
import { default as w } from "./next/client/components/RowndServerStateSync.js";
|
|
5
|
+
export {
|
|
6
|
+
r as RowndProvider,
|
|
7
|
+
w as RowndServerStateSync,
|
|
8
|
+
d as useRownd,
|
|
9
|
+
f as withRowndRequireSignIn
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=next.js.map
|
package/dist/next.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import e, { lazy as r, useCallback as s, Suspense as b } from "react";
|
|
2
|
+
import { RowndContext as p } from "../context/RowndContext.js";
|
|
3
|
+
import d from "../hooks/useHub.js";
|
|
4
|
+
import { InternalRowndProvider as S } from "../context/InternalProvider.js";
|
|
5
|
+
const f = r(
|
|
6
|
+
() => import("../context/HubScriptInjector/InternalProviderHubScriptInjector.js")
|
|
7
|
+
), v = r(() => import("./client/RemixClientScript.js"));
|
|
8
|
+
function H({ children: n, ...o }) {
|
|
9
|
+
const { setInitialHubState: a, hubListenerCb: t } = d(), [l, i] = e.useState({
|
|
10
|
+
...a(),
|
|
11
|
+
onAuthenticated: () => () => {
|
|
12
|
+
}
|
|
13
|
+
}), c = s(({ state: u, api: m }) => {
|
|
14
|
+
t({ state: u, api: m, callback: i });
|
|
15
|
+
}, [t]);
|
|
16
|
+
return /* @__PURE__ */ e.createElement(
|
|
17
|
+
S,
|
|
18
|
+
{
|
|
19
|
+
stateListener: c,
|
|
20
|
+
...o
|
|
21
|
+
},
|
|
22
|
+
/* @__PURE__ */ e.createElement(p.Provider, { value: l }, /* @__PURE__ */ e.createElement(b, { fallback: null }, /* @__PURE__ */ e.createElement(f, null), /* @__PURE__ */ e.createElement(v, null)), n)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
H as RemixRowndProvider
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=RemixRowndProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemixRowndProvider.js","sources":["../../src/remix/RemixRowndProvider.tsx"],"sourcesContent":["import React, { lazy, Suspense, useCallback } from 'react';\nimport { HubListenerProps, RowndContext, RowndProviderProps } from '../context/RowndContext';\nimport useHub from '../hooks/useHub';\nimport { TRowndContext } from '../context/types';\nimport { InternalRowndProvider } from '../context/InternalProvider';\nconst InternalProviderHubScriptInjector = lazy(\n () => import('../context/HubScriptInjector/InternalProviderHubScriptInjector')\n);\nconst RemixClientScript = lazy(() => import('./client/RemixClientScript'));\n\nfunction RemixRowndProvider({ children, ...props }: RowndProviderProps) {\n const { setInitialHubState, hubListenerCb } = useHub();\n\n const [hubState, setHubState] = React.useState<TRowndContext>({\n ...setInitialHubState(),\n onAuthenticated: () => {\n return () => void 0;\n },\n });\n\n const stateListener = useCallback(({ state, api }: HubListenerProps) => {\n hubListenerCb({ state, api, callback: setHubState });\n }, [hubListenerCb]);\n\n return (\n <InternalRowndProvider\n stateListener={stateListener}\n {...props}\n >\n <RowndContext.Provider value={hubState}>\n <Suspense fallback={null}>\n <InternalProviderHubScriptInjector />\n <RemixClientScript />\n </Suspense>\n {children}\n </RowndContext.Provider>\n </InternalRowndProvider>\n );\n}\n\nexport { RemixRowndProvider };\n"],"names":["InternalProviderHubScriptInjector","lazy","RemixClientScript","RemixRowndProvider","children","props","setInitialHubState","hubListenerCb","useHub","hubState","setHubState","React","stateListener","useCallback","state","api","InternalRowndProvider","RowndContext","Suspense"],"mappings":";;;;AAKA,MAAMA,IAAoCC;AAAA,EACxC,MAAM,OAAO,mEAAgE;AAC/E,GACMC,IAAoBD,EAAK,MAAM,OAAO,+BAA4B,CAAC;AAEzE,SAASE,EAAmB,EAAE,UAAAC,GAAU,GAAGC,KAA6B;AACtE,QAAM,EAAE,oBAAAC,GAAoB,eAAAC,EAAA,IAAkBC,EAAA,GAExC,CAACC,GAAUC,CAAW,IAAIC,EAAM,SAAwB;AAAA,IAC5D,GAAGL,EAAA;AAAA,IACH,iBAAiB,MACR;;EACT,CACD,GAEKM,IAAgBC,EAAY,CAAC,EAAE,OAAAC,GAAO,KAAAC,QAA4B;AACtE,IAAAR,EAAc,EAAE,OAAAO,GAAO,KAAAC,GAAK,UAAUL,GAAa;AAAA,EACrD,GAAG,CAACH,CAAa,CAAC;AAElB,SACE,gBAAAI,EAAA;AAAA,IAACK;AAAA,IAAA;AAAA,MACC,eAAAJ;AAAA,MACC,GAAGP;AAAA,IAAA;AAAA,oCAEHY,EAAa,UAAb,EAAsB,OAAOR,KAC5B,gBAAAE,EAAA,cAACO,GAAA,EAAS,UAAU,KAAA,mCACjBlB,GAAA,IAAkC,mCAClCE,GAAA,IAAkB,CACrB,GACCE,CACH;AAAA,EAAA;AAGN;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState as m, useRef as l, useEffect as c } from "react";
|
|
2
|
+
import { useRownd as f } from "./useRownd.js";
|
|
3
|
+
import k from "../../ssr/hooks/useCookie.js";
|
|
4
|
+
import { getOnAuthenticatedListeners as p } from "../../utils/listeners.js";
|
|
5
|
+
const C = () => {
|
|
6
|
+
const { access_token: e, is_initializing: t, user: i, is_authenticated: o } = f(), { cookieSignIn: n, cookieSignOut: r } = k(f), [s, a] = m(!1), u = l(void 0);
|
|
7
|
+
return c(() => {
|
|
8
|
+
if (!(t || u.current === e)) {
|
|
9
|
+
if (u.current = e, !e) {
|
|
10
|
+
a(!1), r();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
n().then(() => a(!0));
|
|
14
|
+
}
|
|
15
|
+
}, [t, e, r, n]), c(() => {
|
|
16
|
+
s && i.data.user_id && !t && o && p().forEach(({ callback: d }) => d(i.data));
|
|
17
|
+
}, [s, i.data.user_id, t, o]), null;
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
C as default
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=RemixClientScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemixClientScript.js","sources":["../../../src/remix/client/RemixClientScript.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { useRownd } from './useRownd';\nimport useCookie from '../../ssr/hooks/useCookie';\nimport { getOnAuthenticatedListeners } from '../../utils/listeners';\n\nconst RemixClientScript: React.FC = () => {\n const { access_token, is_initializing, user, is_authenticated } = useRownd();\n const { cookieSignIn, cookieSignOut } = useCookie(useRownd);\n const [hasCookieSignedIn, setHasCookieSignedIn] = useState(false);\n\n // Listen for access_token changes to determine when to sign(In/Out) cookies and state.\n const prevAccessToken = useRef<string | null | undefined>(undefined);\n useEffect(() => {\n if (is_initializing || prevAccessToken.current === access_token) return;\n\n prevAccessToken.current = access_token;\n\n if (!access_token) {\n setHasCookieSignedIn(false);\n cookieSignOut();\n return;\n }\n\n cookieSignIn().then(() => setHasCookieSignedIn(true));\n }, [is_initializing, access_token, cookieSignOut, cookieSignIn]);\n\n useEffect(() => {\n if (hasCookieSignedIn && Boolean(user.data.user_id) && !is_initializing && is_authenticated) {\n getOnAuthenticatedListeners().forEach(({ callback }) => callback(user.data));\n }\n }, [hasCookieSignedIn, user.data.user_id, is_initializing, is_authenticated]);\n\n return null;\n};\n\nexport default RemixClientScript;\n"],"names":["RemixClientScript","access_token","is_initializing","user","is_authenticated","useRownd","cookieSignIn","cookieSignOut","useCookie","hasCookieSignedIn","setHasCookieSignedIn","useState","prevAccessToken","useRef","useEffect","getOnAuthenticatedListeners","callback"],"mappings":";;;;AAKA,MAAMA,IAA8B,MAAM;AACxC,QAAM,EAAE,cAAAC,GAAc,iBAAAC,GAAiB,MAAAC,GAAM,kBAAAC,EAAA,IAAqBC,EAAA,GAC5D,EAAE,cAAAC,GAAc,eAAAC,MAAkBC,EAAUH,CAAQ,GACpD,CAACI,GAAmBC,CAAoB,IAAIC,EAAS,EAAK,GAG1DC,IAAkBC,EAAkC,MAAS;AACnE,SAAAC,EAAU,MAAM;AACd,QAAI,EAAAZ,KAAmBU,EAAgB,YAAYX,IAInD;AAAA,UAFAW,EAAgB,UAAUX,GAEtB,CAACA,GAAc;AACjB,QAAAS,EAAqB,EAAK,GAC1BH,EAAA;AACA;AAAA,MACF;AAEA,MAAAD,EAAA,EAAe,KAAK,MAAMI,EAAqB,EAAI,CAAC;AAAA;AAAA,EACtD,GAAG,CAACR,GAAiBD,GAAcM,GAAeD,CAAY,CAAC,GAE/DQ,EAAU,MAAM;AACd,IAAIL,KAA6BN,EAAK,KAAK,WAAY,CAACD,KAAmBE,KACzEW,EAAA,EAA8B,QAAQ,CAAC,EAAE,UAAAC,QAAeA,EAASb,EAAK,IAAI,CAAC;AAAA,EAE/E,GAAG,CAACM,GAAmBN,EAAK,KAAK,SAASD,GAAiBE,CAAgB,CAAC,GAErE;AACT;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useCallback as s, useMemo as i } from "react";
|
|
2
|
+
import { useRownd as r } from "../../context/RowndContext.js";
|
|
3
|
+
import "../../context/InternalProvider.js";
|
|
4
|
+
import { addOnAuthenticatedListener as u, unsubscribeOnAuthenticatedListener as c } from "../../utils/listeners.js";
|
|
5
|
+
import { setCookie as a } from "../../ssr/server/cookie.js";
|
|
6
|
+
const g = () => {
|
|
7
|
+
const t = r(), o = s(
|
|
8
|
+
(e) => {
|
|
9
|
+
const n = u(e);
|
|
10
|
+
return () => {
|
|
11
|
+
c(n);
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
[]
|
|
15
|
+
);
|
|
16
|
+
return i(
|
|
17
|
+
() => ({
|
|
18
|
+
...t,
|
|
19
|
+
onAuthenticated: o,
|
|
20
|
+
signOut: async () => {
|
|
21
|
+
try {
|
|
22
|
+
await a("invalid");
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.log("Failed to set sign out cookie: ", e);
|
|
25
|
+
}
|
|
26
|
+
t.signOut();
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
[t]
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
g as useRownd
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useRownd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRownd.js","sources":["../../../src/remix/client/useRownd.tsx"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport { TRowndContext, UserDataContext } from '../../context/types';\nimport { useRownd as useRowndDefault } from '../../index';\nimport { setCookie } from '../../ssr/server/cookie';\nimport { addOnAuthenticatedListener, unsubscribeOnAuthenticatedListener } from '../../utils/listeners';\n\nconst useRownd = (): TRowndContext => {\n const rowndDefault = useRowndDefault();\n\n const onAuthenticated: (\n callback: (userData: UserDataContext) => void\n ) => () => void = useCallback(\n (callback: (userData: UserDataContext) => void) => {\n const id = addOnAuthenticatedListener(callback);\n\n const unsubscribe = () => {\n unsubscribeOnAuthenticatedListener(id);\n };\n\n return unsubscribe;\n },\n []\n );\n\n const memoized = useMemo(\n () => ({\n ...rowndDefault,\n onAuthenticated,\n signOut: async () => {\n // Handle cookie before clearing state\n try {\n await setCookie('invalid');\n } catch (err) {\n console.log('Failed to set sign out cookie: ', err);\n }\n rowndDefault.signOut();\n },\n }),\n [rowndDefault]\n );\n return memoized;\n};\n\nexport { useRownd };\n"],"names":["useRownd","rowndDefault","useRowndDefault","onAuthenticated","useCallback","callback","id","addOnAuthenticatedListener","unsubscribeOnAuthenticatedListener","useMemo","setCookie","err"],"mappings":";;;;;AAMA,MAAMA,IAAW,MAAqB;AACpC,QAAMC,IAAeC,EAAA,GAEfC,IAEYC;AAAA,IAChB,CAACC,MAAkD;AACjD,YAAMC,IAAKC,EAA2BF,CAAQ;AAM9C,aAJoB,MAAM;AACxB,QAAAG,EAAmCF,CAAE;AAAA,MACvC;AAAA,IAGF;AAAA,IACA,CAAA;AAAA,EAAC;AAmBH,SAhBiBG;AAAA,IACf,OAAO;AAAA,MACL,GAAGR;AAAA,MACH,iBAAAE;AAAA,MACA,SAAS,YAAY;AAEnB,YAAI;AACF,gBAAMO,EAAU,SAAS;AAAA,QAC3B,SAASC,GAAK;AACZ,kBAAQ,IAAI,mCAAmCA,CAAG;AAAA,QACpD;AACA,QAAAV,EAAa,QAAA;AAAA,MACf;AAAA,IAAA;AAAA,IAEF,CAACA,CAAY;AAAA,EAAA;AAGjB;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import i, { useState as R, useMemo as c, useRef as S, useEffect as k } from "react";
|
|
2
|
+
import { useRownd as f } from "./useRownd.js";
|
|
3
|
+
import "../../context/RowndContext.js";
|
|
4
|
+
import _ from "../../components/RequireSignIn.js";
|
|
5
|
+
import "../../context/InternalProvider.js";
|
|
6
|
+
import b from "../../ssr/hooks/useCookie.js";
|
|
7
|
+
const P = (d, g, o) => (p) => {
|
|
8
|
+
const { access_token: t, is_initializing: u } = f(), e = g(), [s, w] = R(!1), { cookieSignIn: l, cookieSignOut: a } = b(f), n = c(
|
|
9
|
+
() => (e == null ? void 0 : e.is_authenticated) === !1 || (e == null ? void 0 : e.is_expired) === !0,
|
|
10
|
+
[e == null ? void 0 : e.is_authenticated]
|
|
11
|
+
), r = S(void 0);
|
|
12
|
+
k(() => {
|
|
13
|
+
if (!(u || r.current === t)) {
|
|
14
|
+
if (r.current = t, t && n) {
|
|
15
|
+
l(() => window.location.reload());
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
!t && !n && (w(!0), a(() => window.location.reload()));
|
|
19
|
+
}
|
|
20
|
+
}, [l, u, t, n, a]);
|
|
21
|
+
const m = c(() => o ? /* @__PURE__ */ i.createElement(o, null) : /* @__PURE__ */ i.createElement(i.Fragment, null, "Provide a fallback"), [o]), E = c(() => !n && (!!r.current || s), [n, r.current, s]);
|
|
22
|
+
return s ? m : /* @__PURE__ */ i.createElement(_, { disabled: E }, n ? m : /* @__PURE__ */ i.createElement(d, { ...p }));
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
P as default
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=withRowndRequireSignIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withRowndRequireSignIn.js","sources":["../../../src/remix/client/withRowndRequireSignIn.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react';\nimport { useRownd } from './useRownd';\nimport { RequireSignIn } from '../../index';\nimport useCookie from '../../ssr/hooks/useCookie';\n\nconst withRowndRequireSignIn = <P extends object>(\n WrappedComponent: React.ComponentType<P>,\n useLoaderData: () => any,\n Fallback?: React.ComponentType\n): React.FC<P> => {\n return (props: P) => {\n const { access_token, is_initializing } = useRownd();\n const data = useLoaderData();\n const [signingOut, setSigningOut] = useState(false);\n const { cookieSignIn, cookieSignOut } = useCookie(useRownd);\n\n const isPropsFallbackEnabled = useMemo(\n () => data?.is_authenticated === false || data?.is_expired === true,\n [data?.is_authenticated]\n );\n\n // Trigger cookieSignIn when new accessToken is available.\n const prevAccessToken = useRef<string | null | undefined>(undefined);\n useEffect(() => {\n if (is_initializing || prevAccessToken.current === access_token) {\n return;\n }\n\n prevAccessToken.current = access_token;\n\n if (access_token && isPropsFallbackEnabled) {\n cookieSignIn(() => window.location.reload());\n return;\n }\n\n // Handle sign out\n if (!access_token && !isPropsFallbackEnabled) {\n setSigningOut(true);\n cookieSignOut(() => window.location.reload());\n }\n }, [cookieSignIn, is_initializing, access_token, isPropsFallbackEnabled, cookieSignOut]);\n\n const FallbackElement = useMemo(() => Fallback ? (\n <Fallback />\n ) : (\n <>Provide a fallback</>\n ), [Fallback]);\n\n // This prevents the Hub sign in modal from being shown when the user is signing out.\n const isRequireSignInDisabled = useMemo(() => {\n return !isPropsFallbackEnabled && (Boolean(prevAccessToken.current) || signingOut);\n }, [isPropsFallbackEnabled, prevAccessToken.current, signingOut]);\n\n // If the user is signing out, show the fallback component.\n if (signingOut) {\n return FallbackElement;\n }\n\n return (\n <RequireSignIn disabled={isRequireSignInDisabled}>\n {isPropsFallbackEnabled ? (\n FallbackElement\n ) : (\n <WrappedComponent {...(props as P)} />\n )}\n </RequireSignIn>\n );\n };\n};\n\nexport default withRowndRequireSignIn;\n"],"names":["withRowndRequireSignIn","WrappedComponent","useLoaderData","Fallback","props","access_token","is_initializing","useRownd","data","signingOut","setSigningOut","useState","cookieSignIn","cookieSignOut","useCookie","isPropsFallbackEnabled","useMemo","prevAccessToken","useRef","useEffect","FallbackElement","React","isRequireSignInDisabled","RequireSignIn"],"mappings":";;;;;;AAKA,MAAMA,IAAyB,CAC7BC,GACAC,GACAC,MAEO,CAACC,MAAa;AACnB,QAAM,EAAE,cAAAC,GAAc,iBAAAC,EAAA,IAAoBC,EAAA,GACpCC,IAAON,EAAA,GACP,CAACO,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5C,EAAE,cAAAC,GAAc,eAAAC,MAAkBC,EAAUP,CAAQ,GAEpDQ,IAAyBC;AAAA,IAC7B,OAAMR,KAAA,gBAAAA,EAAM,sBAAqB,OAASA,KAAA,gBAAAA,EAAM,gBAAe;AAAA,IAC/D,CAACA,KAAA,gBAAAA,EAAM,gBAAgB;AAAA,EAAA,GAInBS,IAAkBC,EAAkC,MAAS;AACnE,EAAAC,EAAU,MAAM;AACd,QAAI,EAAAb,KAAmBW,EAAgB,YAAYZ,IAMnD;AAAA,UAFAY,EAAgB,UAAUZ,GAEtBA,KAAgBU,GAAwB;AAC1C,QAAAH,EAAa,MAAM,OAAO,SAAS,OAAA,CAAQ;AAC3C;AAAA,MACF;AAGA,MAAI,CAACP,KAAgB,CAACU,MACpBL,EAAc,EAAI,GAClBG,EAAc,MAAM,OAAO,SAAS,OAAA,CAAQ;AAAA;AAAA,EAEhD,GAAG,CAACD,GAAcN,GAAiBD,GAAcU,GAAwBF,CAAa,CAAC;AAEvF,QAAMO,IAAkBJ,EAAQ,MAAMb,IACpC,gBAAAkB,EAAA,cAAClB,GAAA,IAAS,IAEV,gBAAAkB,EAAA,cAAAA,EAAA,UAAA,MAAE,oBAAkB,GACnB,CAAClB,CAAQ,CAAC,GAGPmB,IAA0BN,EAAQ,MAC/B,CAACD,MAA2B,EAAQE,EAAgB,WAAYR,IACtE,CAACM,GAAwBE,EAAgB,SAASR,CAAU,CAAC;AAGhE,SAAIA,IACKW,IAIP,gBAAAC,EAAA,cAACE,GAAA,EAAc,UAAUD,EAAA,GACtBP,IACCK,IAEA,gBAAAC,EAAA,cAACpB,GAAA,EAAkB,GAAIG,EAAA,CAAa,CAExC;AAEJ;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RemixRowndProvider } from './RemixRowndProvider';
|
|
2
|
+
import { useRownd } from './client/useRownd';
|
|
3
|
+
import { default as RemixClientScript } from './client/RemixClientScript';
|
|
4
|
+
import { default as withRowndRequireSignIn } from './client/withRowndRequireSignIn';
|
|
5
|
+
import { getRowndAuthenticationStatus, withRowndHandleRequest, withRowndLoader } from './server';
|
|
6
|
+
|
|
7
|
+
export { RemixRowndProvider, useRownd, RemixClientScript, withRowndRequireSignIn, getRowndAuthenticationStatus, withRowndHandleRequest, withRowndLoader, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus as a, getRowndUserData as s } from "../../ssr/server/token.js";
|
|
2
|
+
const r = async (e) => {
|
|
3
|
+
const t = await a(
|
|
4
|
+
e.headers.get("Cookie")
|
|
5
|
+
);
|
|
6
|
+
return t.access_token ? await s(t.access_token) : null;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
r as getRowndUser
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getRowndUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRowndUser.js","sources":["../../../src/remix/server/getRowndUser.ts"],"sourcesContent":["import { UserContext } from '../../context/types';\nimport {\n getRowndAuthenticationStatus,\n getRowndUserData,\n} from '../../ssr/server/token';\n\nexport const getRowndUser = async (request: Request): Promise<UserContext | null> => {\n const status = await getRowndAuthenticationStatus(\n request.headers.get('Cookie')\n );\n\n if (!status.access_token) {\n return null;\n }\n\n const userData = await getRowndUserData(status.access_token);\n return userData;\n};\n"],"names":["getRowndUser","request","status","getRowndAuthenticationStatus","getRowndUserData"],"mappings":";AAMO,MAAMA,IAAe,OAAOC,MAAkD;AACnF,QAAMC,IAAS,MAAMC;AAAA,IACnBF,EAAQ,QAAQ,IAAI,QAAQ;AAAA,EAAA;AAG9B,SAAKC,EAAO,eAIK,MAAME,EAAiBF,EAAO,YAAY,IAHlD;AAKX;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getRowndUserId: (request: Request) => Promise<string | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRowndUserId.js","sources":["../../../src/remix/server/getRowndUserId.ts"],"sourcesContent":["import { getRowndAuthenticationStatus } from '../../ssr/server/token';\n\nexport const getRowndUserId = async (request: Request): Promise<string | null> => {\n const status = await getRowndAuthenticationStatus(\n request.headers.get('Cookie')\n );\n\n return status.user_id ?? null;\n};\n"],"names":["getRowndUserId","request","getRowndAuthenticationStatus"],"mappings":";AAEO,MAAMA,IAAiB,OAAOC,OACpB,MAAMC;AAAA,EACnBD,EAAQ,QAAQ,IAAI,QAAQ;AAAA,GAGhB,WAAW;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getRowndAuthenticationStatus } from '../../ssr/server/token';
|
|
2
|
+
import { isAuthenticated } from './isAuthenticated';
|
|
3
|
+
import { withRowndHandleRequest } from './withRowndActionHandler';
|
|
4
|
+
import { withRowndLoader } from './withRowndLoader';
|
|
5
|
+
import { getRowndUser } from './getRowndUser';
|
|
6
|
+
import { getRowndUserId } from './getRowndUserId';
|
|
7
|
+
|
|
8
|
+
export { getRowndAuthenticationStatus, withRowndHandleRequest, withRowndLoader, isAuthenticated, getRowndUser, getRowndUserId, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isAuthenticated: (request: Request) => Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAuthenticated.js","sources":["../../../src/remix/server/isAuthenticated.ts"],"sourcesContent":["import { getRowndAuthenticationStatus } from '../../ssr/server/token';\n\nexport const isAuthenticated = async (request: Request): Promise<boolean> => {\n const status = await getRowndAuthenticationStatus(\n request.headers.get('Cookie')\n );\n\n return status.is_authenticated;\n};\n"],"names":["isAuthenticated","request","getRowndAuthenticationStatus"],"mappings":";AAEO,MAAMA,IAAkB,OAAOC,OACrB,MAAMC;AAAA,EACnBD,EAAQ,QAAQ,IAAI,QAAQ;AAAA,GAGhB;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function withRowndHandleRequest(handleRequest: (request: Request, responseStatusCode: number, responseHeaders: Headers, remixContext: any, loadContext: any) => Promise<unknown>): (request: Request, responseStatusCode: number, responseHeaders: Headers, remixContext: any, loadContext: any) => Promise<unknown>;
|
|
2
|
+
export declare function handleRowndTokenCallback(request: Request): Promise<Response>;
|