@rttnd/gau 0.3.5 → 0.3.6
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Accessor, ParentProps } from 'solid-js';
|
|
1
|
+
import type { Accessor, JSXElement, ParentProps, VoidComponent } from 'solid-js';
|
|
2
2
|
import type { GauSession, ProviderIds } from '../../core';
|
|
3
3
|
interface AuthContextValue<TAuth = unknown> {
|
|
4
4
|
session: Accessor<GauSession<ProviderIds<TAuth>>>;
|
|
@@ -18,5 +18,6 @@ export declare function AuthProvider<const TAuth = unknown>(props: ParentProps &
|
|
|
18
18
|
redirectTo?: string;
|
|
19
19
|
}): import("solid-js").JSX.Element;
|
|
20
20
|
export declare function useAuth<const TAuth = unknown>(): AuthContextValue<TAuth>;
|
|
21
|
+
export declare function Protected<const TAuth = unknown>(page: (session: Accessor<GauSession<ProviderIds<TAuth>>>) => JSXElement, fallbackOrRedirect?: (() => JSXElement) | string): VoidComponent;
|
|
21
22
|
export {};
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/solid/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/solid/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAOzD,UAAU,gBAAgB,CAAC,KAAK,GAAG,OAAO;IACxC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1F,WAAW,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/F,aAAa,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9D,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAID,wBAAgB,YAAY,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,kCAmIhJ;AAED,wBAAgB,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,KAAK,gBAAgB,CAAC,KAAK,CAAC,CAKxE;AAED,wBAAgB,SAAS,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,EAC7C,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,UAAU,EACvE,kBAAkB,CAAC,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,MAAM,GAC/C,aAAa,CAmBf"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/client/solid/index.tsx
|
|
2
|
-
import { createContext, createResource, onCleanup, onMount, untrack, useContext } from "solid-js";
|
|
2
|
+
import { createContext, createResource, onCleanup, onMount, Show, untrack, useContext } from "solid-js";
|
|
3
3
|
import { isServer } from "solid-js/web";
|
|
4
4
|
|
|
5
5
|
// src/core/cookies.ts
|
|
@@ -228,7 +228,23 @@ function useAuth() {
|
|
|
228
228
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
229
229
|
return context;
|
|
230
230
|
}
|
|
231
|
+
function Protected(page, fallbackOrRedirect) {
|
|
232
|
+
return () => {
|
|
233
|
+
const auth = useAuth();
|
|
234
|
+
const isRedirectMode = typeof fallbackOrRedirect === "string" || fallbackOrRedirect === void 0;
|
|
235
|
+
const redirectTo = isRedirectMode ? fallbackOrRedirect ?? "/" : void 0;
|
|
236
|
+
const Fallback = !isRedirectMode ? fallbackOrRedirect : void 0;
|
|
237
|
+
onMount(() => {
|
|
238
|
+
if (isRedirectMode && !auth.session().user && !isServer && redirectTo)
|
|
239
|
+
window.location.href = redirectTo;
|
|
240
|
+
});
|
|
241
|
+
return <Show when={auth.session().user} fallback={Fallback ? <Fallback /> : void 0}>
|
|
242
|
+
{page(auth.session)}
|
|
243
|
+
</Show>;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
231
246
|
export {
|
|
232
247
|
AuthProvider,
|
|
248
|
+
Protected,
|
|
233
249
|
useAuth
|
|
234
250
|
};
|
|
@@ -16,9 +16,9 @@ type AuthInstance<TProviders extends OAuthProvider<any>[]> = ReturnType<typeof c
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare function SvelteKitAuth<const TProviders extends OAuthProvider<any>[]>(optionsOrAuth: CreateAuthOptions<TProviders> | AuthInstance<TProviders>): {
|
|
19
|
-
GET: (event: RequestEvent<
|
|
20
|
-
POST: (event: RequestEvent<
|
|
21
|
-
OPTIONS: (event: RequestEvent<
|
|
19
|
+
GET: (event: RequestEvent<Record<string, string>, string | null>) => Promise<import("..").ResponseLike>;
|
|
20
|
+
POST: (event: RequestEvent<Record<string, string>, string | null>) => Promise<import("..").ResponseLike>;
|
|
21
|
+
OPTIONS: (event: RequestEvent<Record<string, string>, string | null>) => Promise<import("..").ResponseLike>;
|
|
22
22
|
handle: Handle;
|
|
23
23
|
};
|
|
24
24
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rttnd/gau",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.6",
|
|
5
5
|
"packageManager": "bun@1.2.20",
|
|
6
6
|
"description": "gau is a delightful auth library",
|
|
7
7
|
"license": "MIT",
|
|
@@ -141,10 +141,10 @@
|
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
143
|
"@antfu/eslint-config": "^5.2.1",
|
|
144
|
-
"@libsql/client": "^0.15.
|
|
144
|
+
"@libsql/client": "^0.15.12",
|
|
145
145
|
"@types/better-sqlite3": "^7.6.13",
|
|
146
146
|
"@types/bun": "^1.2.20",
|
|
147
|
-
"@types/node": "^24.
|
|
147
|
+
"@types/node": "^24.3.0",
|
|
148
148
|
"@vitest/coverage-v8": "^3.2.4",
|
|
149
149
|
"@vitest/ui": "^3.2.4",
|
|
150
150
|
"better-sqlite3": "^12.2.0",
|