@rttnd/gau 1.2.3 → 1.2.4
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 {
|
|
1
|
+
import type { Accessor, JSXElement, VoidComponent } from 'solid-js';
|
|
2
2
|
import type { GauSession, ProviderIds } from '../../core';
|
|
3
|
-
export declare function Protected<const TAuth = unknown>(page: (session:
|
|
3
|
+
export declare function Protected<const TAuth = unknown>(page: (session: Accessor<GauSession<ProviderIds<TAuth>>>) => JSXElement, fallbackOrRedirect?: (() => JSXElement) | string): VoidComponent;
|
|
4
4
|
//# sourceMappingURL=Protected.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Protected.d.ts","sourceRoot":"","sources":["../../../../src/client/solid/Protected.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Protected.d.ts","sourceRoot":"","sources":["../../../../src/client/solid/Protected.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAMzD,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,CA0Bf"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Accessor, ParentProps, Resource } from 'solid-js';
|
|
2
2
|
import type { GauSession, ProfileName, ProviderIds } from '../../core';
|
|
3
3
|
interface AuthContextValue<TAuth = unknown> {
|
|
4
|
-
session:
|
|
4
|
+
session: Accessor<GauSession<ProviderIds<TAuth>>>;
|
|
5
|
+
isLoading: Accessor<boolean>;
|
|
5
6
|
signIn: <P extends ProviderIds<TAuth>>(provider: P, options?: {
|
|
6
7
|
redirectTo?: string;
|
|
7
8
|
profile?: ProfileName<TAuth, P>;
|
|
@@ -14,12 +15,24 @@ interface AuthContextValue<TAuth = unknown> {
|
|
|
14
15
|
signOut: () => Promise<void>;
|
|
15
16
|
refresh: () => Promise<void>;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
interface AuthProviderProps<TAuth = unknown> extends ParentProps {
|
|
18
19
|
auth?: TAuth;
|
|
19
20
|
baseUrl?: string;
|
|
20
21
|
scheme?: string;
|
|
21
22
|
redirectTo?: string;
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Optional session accessor from `createAsync()` for SSR support.
|
|
25
|
+
* When provided, the session is fetched server-side and serialized into HTML.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const session = createAsync(() => getSession())
|
|
30
|
+
* <AuthProvider session={session}>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
session?: Accessor<GauSession<ProviderIds<TAuth>> | undefined> | Resource<GauSession<ProviderIds<TAuth>>>;
|
|
34
|
+
}
|
|
35
|
+
export declare function AuthProvider<const TAuth = unknown>(props: AuthProviderProps<TAuth>): import("solid-js").JSX.Element;
|
|
23
36
|
export declare function useAuth<const TAuth = unknown>(): AuthContextValue<TAuth>;
|
|
24
37
|
export { Protected } from './Protected';
|
|
25
38
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/solid/index.tsx"],"names":[],"mappings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M,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;CAC1G;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,kCA2JlF;AAED,wBAAgB,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,KAAK,gBAAgB,CAAC,KAAK,CAAC,CAKxE;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -218,7 +218,7 @@ var init_tauri = __esm({
|
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
// src/client/solid/index.tsx
|
|
221
|
-
import { createContext, createResource, onCleanup, onMount as onMount2, untrack, useContext } from "solid-js";
|
|
221
|
+
import { createContext, createMemo, createResource, createSignal, onCleanup, onMount as onMount2, untrack, useContext } from "solid-js";
|
|
222
222
|
import { isServer as isServer2 } from "solid-js/web";
|
|
223
223
|
|
|
224
224
|
// src/core/cookies.ts
|
|
@@ -442,15 +442,44 @@ function AuthProvider(props) {
|
|
|
442
442
|
const client = createAuthClient({
|
|
443
443
|
baseUrl
|
|
444
444
|
});
|
|
445
|
-
const
|
|
446
|
-
|
|
445
|
+
const hasExternalSession = () => props.session !== void 0;
|
|
446
|
+
const [mounted, setMounted] = createSignal(false);
|
|
447
|
+
const fetchSession = async (isMounted) => {
|
|
448
|
+
if (isServer2 || !isMounted)
|
|
447
449
|
return { ...NULL_SESSION, providers: [] };
|
|
448
450
|
return client.refreshSession();
|
|
449
451
|
};
|
|
450
|
-
const [
|
|
452
|
+
const [internalSession, { refetch: internalRefetch }] = createResource(
|
|
453
|
+
mounted,
|
|
451
454
|
fetchSession,
|
|
452
455
|
{ initialValue: { ...NULL_SESSION, providers: [] } }
|
|
453
456
|
);
|
|
457
|
+
const [clientOverride, setClientOverride] = createSignal(null);
|
|
458
|
+
const session = createMemo(() => {
|
|
459
|
+
const override = clientOverride();
|
|
460
|
+
if (override !== null)
|
|
461
|
+
return override;
|
|
462
|
+
if (hasExternalSession()) {
|
|
463
|
+
const ext = props.session();
|
|
464
|
+
return ext ?? { ...NULL_SESSION, providers: [] };
|
|
465
|
+
}
|
|
466
|
+
return internalSession();
|
|
467
|
+
});
|
|
468
|
+
const isLoading = createMemo(() => {
|
|
469
|
+
if (hasExternalSession()) {
|
|
470
|
+
const s = props.session;
|
|
471
|
+
return s?.loading ?? false;
|
|
472
|
+
}
|
|
473
|
+
return internalSession.loading;
|
|
474
|
+
});
|
|
475
|
+
const refetch = async () => {
|
|
476
|
+
if (hasExternalSession()) {
|
|
477
|
+
const refreshed = await client.refreshSession();
|
|
478
|
+
setClientOverride(refreshed);
|
|
479
|
+
} else {
|
|
480
|
+
internalRefetch();
|
|
481
|
+
}
|
|
482
|
+
};
|
|
454
483
|
async function signIn(provider, { redirectTo, profile } = {}) {
|
|
455
484
|
const inTauri = !isServer2 && isTauri();
|
|
456
485
|
let finalRedirectTo = redirectTo ?? props.redirectTo;
|
|
@@ -481,20 +510,23 @@ function AuthProvider(props) {
|
|
|
481
510
|
async function unlinkAccount(provider) {
|
|
482
511
|
const ok = await client.unlinkAccount(provider);
|
|
483
512
|
if (ok)
|
|
484
|
-
refetch();
|
|
513
|
+
await refetch();
|
|
485
514
|
else
|
|
486
515
|
console.error("Failed to unlink account");
|
|
487
516
|
}
|
|
488
517
|
const signOut = async () => {
|
|
489
518
|
await client.signOut();
|
|
490
|
-
refetch();
|
|
519
|
+
await refetch();
|
|
491
520
|
};
|
|
492
521
|
onMount2(() => {
|
|
522
|
+
if (!untrack(hasExternalSession))
|
|
523
|
+
setMounted(true);
|
|
524
|
+
const doRefetch = untrack(() => refetch);
|
|
493
525
|
if (!isTauri()) {
|
|
494
526
|
void (async () => {
|
|
495
527
|
const handled = await client.handleRedirectCallback();
|
|
496
528
|
if (handled)
|
|
497
|
-
|
|
529
|
+
await doRefetch();
|
|
498
530
|
})();
|
|
499
531
|
return;
|
|
500
532
|
}
|
|
@@ -503,7 +535,7 @@ function AuthProvider(props) {
|
|
|
503
535
|
const { startAuthBridge: startAuthBridge2 } = await Promise.resolve().then(() => (init_tauri(), tauri_exports));
|
|
504
536
|
const unlisten = await startAuthBridge2(baseUrl, scheme, async (token) => {
|
|
505
537
|
await client.applySessionToken(token);
|
|
506
|
-
|
|
538
|
+
await doRefetch();
|
|
507
539
|
});
|
|
508
540
|
if (disposed)
|
|
509
541
|
unlisten?.();
|
|
@@ -514,9 +546,7 @@ function AuthProvider(props) {
|
|
|
514
546
|
disposed = true;
|
|
515
547
|
});
|
|
516
548
|
});
|
|
517
|
-
return <AuthContext.Provider value={{ session, signIn, linkAccount, unlinkAccount, signOut, refresh:
|
|
518
|
-
await refetch();
|
|
519
|
-
} }}>
|
|
549
|
+
return <AuthContext.Provider value={{ session, isLoading, signIn, linkAccount, unlinkAccount, signOut, refresh: refetch }}>
|
|
520
550
|
{props.children}
|
|
521
551
|
</AuthContext.Provider>;
|
|
522
552
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rttnd/gau",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
5
|
-
"packageManager": "bun@1.3.
|
|
4
|
+
"version": "1.2.4",
|
|
5
|
+
"packageManager": "bun@1.3.5",
|
|
6
6
|
"description": "gau is a delightful auth library",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/Rettend/gau#readme",
|
|
@@ -154,28 +154,28 @@
|
|
|
154
154
|
"dependencies": {
|
|
155
155
|
"@oslojs/jwt": "^0.3.0",
|
|
156
156
|
"arctic": "^3.7.0",
|
|
157
|
-
"cookie": "^1.
|
|
157
|
+
"cookie": "^1.1.1",
|
|
158
158
|
"esm-env": "^1.2.2"
|
|
159
159
|
},
|
|
160
160
|
"devDependencies": {
|
|
161
|
-
"@antfu/eslint-config": "^6.
|
|
162
|
-
"@electric-sql/pglite": "^0.3.
|
|
161
|
+
"@antfu/eslint-config": "^6.7.1",
|
|
162
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
163
163
|
"@libsql/client": "^0.15.15",
|
|
164
|
-
"@solidjs/router": "^0.15.
|
|
165
|
-
"@sveltejs/kit": "^2.
|
|
166
|
-
"@tauri-apps/api": "^2.
|
|
167
|
-
"@tauri-apps/plugin-opener": "^2.
|
|
164
|
+
"@solidjs/router": "^0.15.4",
|
|
165
|
+
"@sveltejs/kit": "^2.49.2",
|
|
166
|
+
"@tauri-apps/api": "^2.9.1",
|
|
167
|
+
"@tauri-apps/plugin-opener": "^2.5.2",
|
|
168
168
|
"@types/better-sqlite3": "^7.6.13",
|
|
169
|
-
"@types/bun": "^1.3.
|
|
170
|
-
"@types/node": "^
|
|
171
|
-
"@vitest/coverage-v8": "^
|
|
172
|
-
"@vitest/ui": "^
|
|
173
|
-
"better-sqlite3": "^12.
|
|
174
|
-
"bumpp": "^10.3.
|
|
175
|
-
"drizzle-kit": "^0.31.
|
|
176
|
-
"drizzle-orm": "^0.
|
|
177
|
-
"eslint": "^9.
|
|
178
|
-
"solid-js": "^1.9.
|
|
179
|
-
"vitest": "^
|
|
169
|
+
"@types/bun": "^1.3.5",
|
|
170
|
+
"@types/node": "^25.0.3",
|
|
171
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
172
|
+
"@vitest/ui": "^4.0.16",
|
|
173
|
+
"better-sqlite3": "^12.5.0",
|
|
174
|
+
"bumpp": "^10.3.2",
|
|
175
|
+
"drizzle-kit": "^0.31.8",
|
|
176
|
+
"drizzle-orm": "^0.45.1",
|
|
177
|
+
"eslint": "^9.39.2",
|
|
178
|
+
"solid-js": "^1.9.10",
|
|
179
|
+
"vitest": "^4.0.16"
|
|
180
180
|
}
|
|
181
181
|
}
|