@fluxbase/sdk 0.0.1-rc.116 → 0.0.1-rc.117
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/dist/index.cjs +17 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3845,8 +3845,9 @@ declare class FluxbaseAuth {
|
|
|
3845
3845
|
* Exchange OAuth authorization code for session
|
|
3846
3846
|
* This is typically called in your OAuth callback handler
|
|
3847
3847
|
* @param code - Authorization code from OAuth callback
|
|
3848
|
+
* @param state - State parameter from OAuth callback (for CSRF protection)
|
|
3848
3849
|
*/
|
|
3849
|
-
exchangeCodeForSession(code: string): Promise<FluxbaseAuthResponse>;
|
|
3850
|
+
exchangeCodeForSession(code: string, state?: string): Promise<FluxbaseAuthResponse>;
|
|
3850
3851
|
/**
|
|
3851
3852
|
* Convenience method to initiate OAuth sign-in
|
|
3852
3853
|
* Redirects the user to the OAuth provider's authorization page
|
package/dist/index.d.ts
CHANGED
|
@@ -3845,8 +3845,9 @@ declare class FluxbaseAuth {
|
|
|
3845
3845
|
* Exchange OAuth authorization code for session
|
|
3846
3846
|
* This is typically called in your OAuth callback handler
|
|
3847
3847
|
* @param code - Authorization code from OAuth callback
|
|
3848
|
+
* @param state - State parameter from OAuth callback (for CSRF protection)
|
|
3848
3849
|
*/
|
|
3849
|
-
exchangeCodeForSession(code: string): Promise<FluxbaseAuthResponse>;
|
|
3850
|
+
exchangeCodeForSession(code: string, state?: string): Promise<FluxbaseAuthResponse>;
|
|
3850
3851
|
/**
|
|
3851
3852
|
* Convenience method to initiate OAuth sign-in
|
|
3852
3853
|
* Redirects the user to the OAuth provider's authorization page
|
package/dist/index.js
CHANGED
|
@@ -331,6 +331,7 @@ async function wrapAsyncVoid(operation) {
|
|
|
331
331
|
|
|
332
332
|
// src/auth.ts
|
|
333
333
|
var AUTH_STORAGE_KEY = "fluxbase.auth.session";
|
|
334
|
+
var OAUTH_PROVIDER_KEY = "fluxbase.auth.oauth_provider";
|
|
334
335
|
var AUTO_REFRESH_TICK_THRESHOLD = 10;
|
|
335
336
|
var AUTO_REFRESH_TICK_MINIMUM = 1e3;
|
|
336
337
|
var MAX_REFRESH_RETRIES = 3;
|
|
@@ -908,13 +909,24 @@ var FluxbaseAuth = class {
|
|
|
908
909
|
* Exchange OAuth authorization code for session
|
|
909
910
|
* This is typically called in your OAuth callback handler
|
|
910
911
|
* @param code - Authorization code from OAuth callback
|
|
912
|
+
* @param state - State parameter from OAuth callback (for CSRF protection)
|
|
911
913
|
*/
|
|
912
|
-
async exchangeCodeForSession(code) {
|
|
914
|
+
async exchangeCodeForSession(code, state) {
|
|
913
915
|
return wrapAsync(async () => {
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
|
|
916
|
+
const provider = this.storage?.getItem(OAUTH_PROVIDER_KEY);
|
|
917
|
+
if (!provider) {
|
|
918
|
+
throw new Error(
|
|
919
|
+
"No OAuth provider found. Call signInWithOAuth first."
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
const params = new URLSearchParams({ code });
|
|
923
|
+
if (state) {
|
|
924
|
+
params.append("state", state);
|
|
925
|
+
}
|
|
926
|
+
const response = await this.fetch.get(
|
|
927
|
+
`/api/v1/auth/oauth/${provider}/callback?${params.toString()}`
|
|
917
928
|
);
|
|
929
|
+
this.storage?.removeItem(OAUTH_PROVIDER_KEY);
|
|
918
930
|
const session = {
|
|
919
931
|
...response,
|
|
920
932
|
expires_at: Date.now() + response.expires_in * 1e3
|
|
@@ -937,6 +949,7 @@ var FluxbaseAuth = class {
|
|
|
937
949
|
}
|
|
938
950
|
const url = result.data.url;
|
|
939
951
|
if (typeof window !== "undefined") {
|
|
952
|
+
this.storage?.setItem(OAUTH_PROVIDER_KEY, provider);
|
|
940
953
|
window.location.href = url;
|
|
941
954
|
} else {
|
|
942
955
|
throw new Error(
|