@samebase/convex-auth-tanstack-start 0.1.0 → 0.1.2
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/CHANGELOG.md +11 -0
- package/README.md +7 -5
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- `useSignOutSession` loads `landingUrl` with `location.replace`, so Back after a sign-out no longer
|
|
6
|
+
returns to the page of the session that ended.
|
|
7
|
+
|
|
8
|
+
## 0.1.1
|
|
9
|
+
|
|
10
|
+
- `useSignOutSession(url, landingUrl)` loads `landingUrl` after the sign-out instead of reloading
|
|
11
|
+
the page. A reload asked the server for the private page the visitor signed out on, and the app's
|
|
12
|
+
gate answered with its sign-in redirect, so the visitor landed on `/?next=/settings`.
|
|
13
|
+
|
|
3
14
|
## 0.1.0
|
|
4
15
|
|
|
5
16
|
- The `convex-auth` entry of `@samebase/convex-hosting-tanstack-start` 0.10.2, as a package of its
|
package/README.md
CHANGED
|
@@ -130,11 +130,13 @@ Without `next`, the gate is `redirectWithoutSession(serverContext, { to: "/signi
|
|
|
130
130
|
Convex's provider reports loading during the server render and the hydration, so the token that
|
|
131
131
|
`SessionProvider` was given decides until it settles, and both renders agree, where Convex's
|
|
132
132
|
`Authenticated` and `Unauthenticated` render nothing on the server.
|
|
133
|
-
- `useSignOutSession(url)`: returns a function that posts to the app's sign-out route,
|
|
134
|
-
`/auth/signout`, and only after a 2xx calls Convex Auth's `signOut()`, which clears the
|
|
135
|
-
token in every tab, and
|
|
136
|
-
|
|
137
|
-
the
|
|
133
|
+
- `useSignOutSession(url, landingUrl)`: returns a function that posts to the app's sign-out route,
|
|
134
|
+
such as `/auth/signout`, and only after a 2xx calls Convex Auth's `signOut()`, which clears the
|
|
135
|
+
stored token in every tab, and loads `landingUrl`, such as `/`, in place of the current history
|
|
136
|
+
entry; otherwise it returns `false` and the session stays. A reload of the page the visitor signed
|
|
137
|
+
out on would ask the server for a private page without a session, and a gate would answer with its
|
|
138
|
+
sign-in redirect and `next`. Convex Auth's `signOut()` resolves even when the route failed, so a
|
|
139
|
+
reload after it alone signs the user back in from the cookie.
|
|
138
140
|
|
|
139
141
|
`@convex-dev/auth` is a peer dependency pinned to 2.0.0-beta.0, because `convexAuth()` resolves a
|
|
140
142
|
file inside that version. An app on Convex Auth 0.0.x stays on
|
package/dist/index.d.ts
CHANGED
|
@@ -54,10 +54,13 @@ export declare function SignedOut({ children }: {
|
|
|
54
54
|
* to the route; when it fails or cannot be reached, it returns `false` and changes nothing, because
|
|
55
55
|
* the cookie and the session stay. Convex Auth's `signOut()` resolves even when the route failed, so
|
|
56
56
|
* the route's answer decides. After a 2xx, `signOut()` clears the stored access token and tells the
|
|
57
|
-
* other tabs (its own call to the route is then redundant), and the
|
|
58
|
-
* `expectAuth` holds queries only before the first
|
|
57
|
+
* other tabs (its own call to the route is then redundant), and the browser loads `landingUrl`,
|
|
58
|
+
* such as `/`, with a full load, because `expectAuth` holds queries only before the first
|
|
59
|
+
* authentication. Not a reload: the page the visitor signed out on is usually private, and a
|
|
60
|
+
* request for it without a session gets the gate's sign-in redirect with `next`. The load replaces
|
|
61
|
+
* the current history entry: Back after a sign-out skips the page of the session that ended.
|
|
59
62
|
*/
|
|
60
|
-
export declare function useSignOutSession(url: string): () => Promise<boolean>;
|
|
63
|
+
export declare function useSignOutSession(url: string, landingUrl: string): () => Promise<boolean>;
|
|
61
64
|
/**
|
|
62
65
|
* A gate's `beforeLoad`: a server render without a session throws `redirect(options)`, whether it
|
|
63
66
|
* found none or knows nothing about one. Only the server render has the cookie; a browser
|
package/dist/index.js
CHANGED
|
@@ -77,17 +77,20 @@ export function SignedOut({ children }) {
|
|
|
77
77
|
* to the route; when it fails or cannot be reached, it returns `false` and changes nothing, because
|
|
78
78
|
* the cookie and the session stay. Convex Auth's `signOut()` resolves even when the route failed, so
|
|
79
79
|
* the route's answer decides. After a 2xx, `signOut()` clears the stored access token and tells the
|
|
80
|
-
* other tabs (its own call to the route is then redundant), and the
|
|
81
|
-
* `expectAuth` holds queries only before the first
|
|
80
|
+
* other tabs (its own call to the route is then redundant), and the browser loads `landingUrl`,
|
|
81
|
+
* such as `/`, with a full load, because `expectAuth` holds queries only before the first
|
|
82
|
+
* authentication. Not a reload: the page the visitor signed out on is usually private, and a
|
|
83
|
+
* request for it without a session gets the gate's sign-in redirect with `next`. The load replaces
|
|
84
|
+
* the current history entry: Back after a sign-out skips the page of the session that ended.
|
|
82
85
|
*/
|
|
83
|
-
export function useSignOutSession(url) {
|
|
86
|
+
export function useSignOutSession(url, landingUrl) {
|
|
84
87
|
const { signOut } = useAuthActions();
|
|
85
88
|
return async () => {
|
|
86
89
|
const response = await fetch(url, { method: "POST", credentials: "include" }).catch(() => null);
|
|
87
90
|
if (!response?.ok)
|
|
88
91
|
return false;
|
|
89
92
|
await signOut();
|
|
90
|
-
location.
|
|
93
|
+
location.replace(landingUrl);
|
|
91
94
|
return true;
|
|
92
95
|
};
|
|
93
96
|
}
|