@orsetra/shared-auth 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-auth",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Shared authentication utilities for Orsetra platform using Zitadel",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",
@@ -9,7 +9,7 @@
9
9
  "./config": "./config/zitadel.config.ts",
10
10
  "./services": "./services/zitadel.auth.service.ts",
11
11
  "./components": "./components/index.ts",
12
- "./utils": "./utils/redirect-utils.ts"
12
+ "./utils": "./utils/index.ts"
13
13
  },
14
14
  "files": [
15
15
  "index.ts",
package/utils/index.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './token-validator'
2
- export * from '../redirect-utils'
2
+ export * from './redirect-utils'
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Utilitaires pour gérer les redirections après authentification
3
+ */
4
+
5
+ const REDIRECT_KEY = 'zitadel_redirect_url'
6
+
7
+ /**
8
+ * Sauvegarde l'URL actuelle pour redirection après authentification
9
+ */
10
+ export function saveRedirectUrl(url?: string): void {
11
+ if (typeof window === 'undefined') return
12
+
13
+ const urlToSave = url || window.location.pathname + window.location.search
14
+ sessionStorage.setItem(REDIRECT_KEY, urlToSave)
15
+ }
16
+
17
+ /**
18
+ * Récupère et supprime l'URL de redirection sauvegardée
19
+ * @param fallback URL par défaut si aucune redirection n'est sauvegardée
20
+ * @returns L'URL de redirection
21
+ */
22
+ export function getAndClearRedirectUrl(fallback: string = ''): string {
23
+ if (typeof window === 'undefined') return fallback
24
+
25
+ const redirectUrl = sessionStorage.getItem(REDIRECT_KEY)
26
+ sessionStorage.removeItem(REDIRECT_KEY)
27
+
28
+ return redirectUrl || fallback
29
+ }
30
+
31
+ /**
32
+ * Vérifie si une URL de redirection est sauvegardée
33
+ */
34
+ export function hasRedirectUrl(): boolean {
35
+ if (typeof window === 'undefined') return false
36
+ return sessionStorage.getItem(REDIRECT_KEY) !== null
37
+ }
38
+
39
+ /**
40
+ * Nettoie l'URL de redirection sauvegardée
41
+ */
42
+ export function clearRedirectUrl(): void {
43
+ if (typeof window === 'undefined') return
44
+ sessionStorage.removeItem(REDIRECT_KEY)
45
+ }