@pylonsync/next 0.3.5 → 0.3.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/auth.ts +24 -3
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.5",
6
+ "version": "0.3.7",
7
7
  "type": "module",
8
8
  "description": "Next.js helpers for Pylon — cookie-based auth gate, server-side session helpers, and reusable client hooks.",
9
9
  "exports": {
package/src/auth.ts CHANGED
@@ -67,12 +67,33 @@ export async function listOAuthProviders(): Promise<OAuthProvider[]> {
67
67
  /**
68
68
  * Kick off an OAuth login. Browser navigates to Pylon's GET login
69
69
  * route, which 302s to the provider, which 302s back to Pylon's GET
70
- * callback (Set-Cookie + 302 to PYLON_DASHBOARD_URL). The OAuth code
70
+ * callback (Set-Cookie + 302 to the success URL). The OAuth code
71
71
  * never enters JS, so XSS in the dashboard can't intercept the
72
72
  * handshake.
73
+ *
74
+ * `successUrl` and `errorUrl` MUST have origins listed in the
75
+ * server's PYLON_TRUSTED_ORIGINS — otherwise pylon's start endpoint
76
+ * 403s with UNTRUSTED_REDIRECT. Defaults are sensible for typical
77
+ * Next.js layouts (current origin's `/dashboard` and `/login`); pass
78
+ * explicit values for apps that route auth elsewhere.
73
79
  */
74
- export function startOAuthLogin(provider: OAuthProvider["provider"]): void {
75
- window.location.href = `/api/auth/login/${provider}?redirect=1`;
80
+ export type StartOAuthLoginOptions = {
81
+ successUrl?: string;
82
+ errorUrl?: string;
83
+ };
84
+ export function startOAuthLogin(
85
+ provider: OAuthProvider["provider"],
86
+ opts: StartOAuthLoginOptions = {},
87
+ ): void {
88
+ const origin = window.location.origin;
89
+ const successUrl = opts.successUrl ?? `${origin}/dashboard`;
90
+ const errorUrl = opts.errorUrl ?? `${origin}/login`;
91
+ const params = new URLSearchParams({
92
+ redirect: "1",
93
+ callback: successUrl,
94
+ error_callback: errorUrl,
95
+ });
96
+ window.location.href = `/api/auth/login/${provider}?${params.toString()}`;
76
97
  }
77
98
 
78
99
  export async function sendVerificationEmail(): Promise<{