@@ -67,6 +67,37 @@ interface TokenSessionParams {
67
67
onUpdate : ( _state : TokenSessionState ) => void
68
68
}
69
69
70
+ /**
71
+ * Creates a token-based session where the provided token is validated, parsed,
72
+ * and extended with the specified options. The resulting authentication state
73
+ * is returned when the callback method is triggered.
74
+ *
75
+ * @param params.token - The token to be validated, parsed, and extended with the given options.
76
+ * @param params.onUpdate - A callback function invoked on login and logout events.
77
+ * @param params.initialLogin - A boolean indicating whether the login should be performed immediately
78
+ * on the first call, triggering the callback method.
79
+ * @param params.options - Additional options to extend the token data.
80
+ * See the following documentation for details on the returned auth data structure
81
+ * and usage of the `options` parameter:
82
+ * [Juno Auth Data Documentation](https://github.com/cloudoperators/juno/blob/main/packages/oauth/README.md#auth-data)
83
+ *
84
+ * @returns An object containing the following methods:
85
+ * - `login()`: Triggers the login process.
86
+ * - `logout()`: Triggers the logout process.
87
+ * - `currentState()`: Returns the current authentication state.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const session = tokenSession({
92
+ * token: jwtToken,
93
+ * options: {
94
+ * groups: [`organization:${demoOrg}`],
95
+ * },
96
+ * onUpdate: (authData) => {
97
+ * saveAuthData(authData);
98
+ * },
99
+ * });
100
+ */
70
101
export default function tokenSession ( params : TokenSessionParams ) : TokenSessionReturnType {
71
102
const { token, onUpdate, initialLogin, options } = params || { }
72
103
0 commit comments