@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.
- package/dist/auth/route-guard.js +5 -5
- package/dist/client/BridgeBootstrap.js +3 -3
- package/dist/client/components/auth/Login.svelte +1 -1
- package/dist/client/components/team/TeamManagement.svelte +3 -3
- package/dist/shared/services/auth.service.d.ts +1 -1
- package/dist/shared/services/auth.service.js +4 -4
- package/dist/shared/types/config.d.ts +1 -1
- package/package.json +1 -1
package/dist/auth/route-guard.js
CHANGED
|
@@ -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 {
|
|
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
|
|
61
|
-
if (isProtectedRoute(pathname) && !get(
|
|
62
|
-
logger.debug(`[route-guard] path ${pathname} is protected and user is not
|
|
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 ${
|
|
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
|
-
|
|
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
|
-
|
|
43
|
+
redirect(303, auth.createLoginUrl());
|
|
44
44
|
}
|
|
45
45
|
if (decision.type === 'redirect' && url.pathname !== decision.to) {
|
|
46
|
-
|
|
46
|
+
redirect(303, decision.to);
|
|
47
47
|
}
|
|
48
48
|
logger.debug('[bridgeBootstrap] in bridge end');
|
|
49
49
|
}
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
onMount(async () => {
|
|
50
50
|
logger.debug('TeamManagement onMount');
|
|
51
51
|
try {
|
|
52
|
-
if (!auth.
|
|
53
|
-
logger.debug('TeamManagement onMount: User is not
|
|
54
|
-
throw new Error('User must be
|
|
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
|
-
|
|
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
|
|
195
|
+
const isAuthenticated = derived(tokenStore, $t => !!$t?.accessToken);
|
|
196
196
|
// --- Exports ---
|
|
197
197
|
export const auth = {
|
|
198
198
|
token: tokenStore,
|
|
199
|
-
|
|
199
|
+
isAuthenticated,
|
|
200
200
|
isLoading,
|
|
201
201
|
error,
|
|
202
202
|
login,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebulr-group/bridge-svelte",
|
|
3
|
-
"version": "0.1.0
|
|
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",
|