Skip to content

Commit fe294e9

Browse files
authored
chore(oauth): adds method documentation and types refactoring (#772)
* chore(oauth): adds method documentation and types refactoring * chore(oauth): make use of interfaces since it is the recommendation
1 parent 58925a1 commit fe294e9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.changeset/silly-hornets-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudoperators/juno-oauth": patch
3+
---
4+
5+
Improving types and addind method documentation

packages/oauth/src/tokenSession.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,37 @@ interface TokenSessionParams {
6767
onUpdate: (_state: TokenSessionState) => void
6868
}
6969

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+
*/
70101
export default function tokenSession(params: TokenSessionParams): TokenSessionReturnType {
71102
const { token, onUpdate, initialLogin, options } = params || {}
72103

0 commit comments

Comments
 (0)