@nebulr-group/bridge-svelte 0.1.0-beta.1 → 0.1.0

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.
@@ -3,7 +3,7 @@ import { getRouteGuardConfig } from '../client/stores/config.store.js';
3
3
  import { isFeatureEnabled } from '../shared/feature-flag.js';
4
4
  import { logger } from '../shared/logger.js';
5
5
  import { auth } from '../shared/services/auth.service.js';
6
- const { isAubridgenticated, createLoginUrl } = auth;
6
+ const { isAuthenticated, createLoginUrl } = auth;
7
7
  function escapeRegex(text) {
8
8
  return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
9
9
  }
@@ -57,12 +57,12 @@ export function createRouteGuard() {
57
57
  }
58
58
  function shouldRedirectToLogin(pathname) {
59
59
  const isProtected = isProtectedRoute(pathname);
60
- const aubridgenticated = get(isAubridgenticated);
61
- if (isProtectedRoute(pathname) && !get(isAubridgenticated)) {
62
- logger.debug(`[route-guard] path ${pathname} is protected and user is not aubridgenticated`);
60
+ const authenticated = get(isAuthenticated);
61
+ if (isProtectedRoute(pathname) && !get(isAuthenticated)) {
62
+ logger.debug(`[route-guard] path ${pathname} is protected and user is not authenticated`);
63
63
  return true;
64
64
  }
65
- logger.debug(`[route-guard] path ${pathname} is ${isProtected ? 'protected' : 'public'} and user ${aubridgenticated ? 'aubridgenticated' : 'not aubridgenticated'}`);
65
+ logger.debug(`[route-guard] path ${pathname} is ${isProtected ? 'protected' : 'public'} and user ${authenticated ? 'authenticated' : 'not authenticated'}`);
66
66
  return false;
67
67
  }
68
68
  async function checkRouteRestrictions(pathname) {
@@ -20,7 +20,7 @@ export async function bridgeBootstrap(url, config, routeConfig = { rules: [], de
20
20
  try {
21
21
  await handleCallback(code);
22
22
  // Redirect bridge user to bridge home page after bridge callback is handled
23
- window.location.href = '/';
23
+ redirect(303, '/');
24
24
  }
25
25
  catch (err) {
26
26
  logger.error('Auth callback error:', err);
@@ -40,10 +40,10 @@ export async function bridgeBootstrap(url, config, routeConfig = { rules: [], de
40
40
  const decision = await guard.getNavigationDecision(url.pathname);
41
41
  logger.debug('[bridgeBootstrap] navigation decision', decision);
42
42
  if (decision.type === 'login') {
43
- throw redirect(303, auth.createLoginUrl());
43
+ redirect(303, auth.createLoginUrl());
44
44
  }
45
45
  if (decision.type === 'redirect' && url.pathname !== decision.to) {
46
- throw redirect(303, decision.to);
46
+ redirect(303, decision.to);
47
47
  }
48
48
  logger.debug('[bridgeBootstrap] in bridge end');
49
49
  }
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { auth } from '../../../shared/services/auth.service';
3
- const { isAubridgenticated, login } = auth;
3
+ const { isAuthenticated, login } = auth;
4
4
  </script>
5
5
 
6
6
  <button onclick={() => login()} class="login-button">
@@ -49,9 +49,9 @@
49
49
  onMount(async () => {
50
50
  logger.debug('TeamManagement onMount');
51
51
  try {
52
- if (!auth.isAubridgenticated) {
53
- logger.debug('TeamManagement onMount: User is not aubridgenticated');
54
- throw new Error('User must be aubridgenticated to access team management');
52
+ if (!auth.isAuthenticated) {
53
+ logger.debug('TeamManagement onMount: User is not authenticated');
54
+ throw new Error('User must be authenticated to access team management');
55
55
  }
56
56
  const token = auth.getToken();
57
57
  // Get bridge access token from your auth store
@@ -10,7 +10,7 @@ declare function handleCallback(code: string): Promise<void>;
10
10
  declare function refreshToken(refreshToken: string): Promise<TokenSet | null>;
11
11
  export declare const auth: {
12
12
  token: import("svelte/store").Writable<any>;
13
- isAubridgenticated: import("svelte/store").Readable<boolean>;
13
+ isAuthenticated: import("svelte/store").Readable<boolean>;
14
14
  isLoading: import("svelte/store").Writable<boolean>;
15
15
  error: import("svelte/store").Writable<string | null>;
16
16
  login: typeof login;
@@ -49,7 +49,7 @@ function createLoginUrl(options = {}) {
49
49
  const config = getConfig();
50
50
  const redirectUri = options.redirectUri ?? config.callbackUrl;
51
51
  const base = `${config.authBaseUrl}/url/login/${config.appId}`;
52
- return redirectUri ? `${base}?redirect_uri=${encodeURIComponent(redirectUri)}` : base;
52
+ return redirectUri ? `${base}?cv_env=bridge&redirect_uri=${encodeURIComponent(redirectUri)}` : base;
53
53
  }
54
54
  async function handleCallback(code) {
55
55
  const config = getConfig();
@@ -59,7 +59,7 @@ async function handleCallback(code) {
59
59
  headers: { 'Content-Type': 'application/json' },
60
60
  body: JSON.stringify({
61
61
  code,
62
- ...(config.callbackUrl ? { redirect_uri: config.callbackUrl } : {})
62
+ ...(config.callbackUrl ? { redirect_uri: config.callbackUrl, redirectUri: config.callbackUrl } : {})
63
63
  })
64
64
  });
65
65
  if (!response.ok) {
@@ -192,11 +192,11 @@ export async function maybeRefreshNow() {
192
192
  return true;
193
193
  }
194
194
  // --- Derived values ---
195
- const isAubridgenticated = derived(tokenStore, $t => !!$t?.accessToken);
195
+ const isAuthenticated = derived(tokenStore, $t => !!$t?.accessToken);
196
196
  // --- Exports ---
197
197
  export const auth = {
198
198
  token: tokenStore,
199
- isAubridgenticated,
199
+ isAuthenticated,
200
200
  isLoading,
201
201
  error,
202
202
  login,
@@ -25,7 +25,7 @@ export interface BridgeConfig {
25
25
  */
26
26
  defaultRedirectRoute?: string;
27
27
  /**
28
- * Route to redirect to when aubridgentication fails
28
+ * Route to redirect to when authentication fails
29
29
  * @default '/login'
30
30
  */
31
31
  loginRoute?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebulr-group/bridge-svelte",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0",
4
4
 
5
5
  "description": "Bridge Svelte library, This library helps you to add bridge authentication and feature flags, and payments to your svelte application.",
6
6
  "author": "Iman Pouya",