@foru-ms/sdk 1.2.8 → 1.3.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/README.md +5 -1
- package/dist/resources/Auth.d.ts +2 -2
- package/dist/resources/Auth.js +5 -1
- package/dist/types.d.ts +4 -0
- package/examples/authentication.ts +5 -5
- package/package.json +1 -1
- package/src/resources/Auth.ts +9 -3
- package/src/types.ts +5 -0
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ Check the `/examples` directory for detailed examples:
|
|
|
201
201
|
### Auth (`client.auth`)
|
|
202
202
|
|
|
203
203
|
* `login(payload: { login: string; password: string })`: Login a user. Returns `{ token: string }`.
|
|
204
|
-
* `register(payload: RegisterPayload)`: Register a new user.
|
|
204
|
+
* `register(payload: RegisterPayload)`: Register a new user. Returns `{ user: User, token: string }`. Token is automatically set on the client.
|
|
205
205
|
* `me()`: Get specific details of the currently authenticated user.
|
|
206
206
|
* `forgotPassword(email: string)`: Initiate password reset flow.
|
|
207
207
|
* `resetPassword(payload: { password: string; oldPassword?: string; email?: string; token?: string })`: Reset password using token or old password.
|
|
@@ -382,6 +382,7 @@ import {
|
|
|
382
382
|
RegisterPayload,
|
|
383
383
|
User,
|
|
384
384
|
LoginResponse,
|
|
385
|
+
RegisterResponse,
|
|
385
386
|
SecurityInfo,
|
|
386
387
|
|
|
387
388
|
// Thread Types
|
|
@@ -552,6 +553,9 @@ We welcome contributions! Please see our contributing guidelines for more inform
|
|
|
552
553
|
|
|
553
554
|
## Changelog
|
|
554
555
|
|
|
556
|
+
### v1.3.0
|
|
557
|
+
- Added Auth resource, authentication example, and related types
|
|
558
|
+
|
|
555
559
|
### v1.2.8
|
|
556
560
|
- Added Poll resource for poll management
|
|
557
561
|
|
package/dist/resources/Auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
|
-
import { LoginResponse } from '../types';
|
|
2
|
+
import { LoginResponse, RegisterResponse } from '../types';
|
|
3
3
|
export declare class AuthResource {
|
|
4
4
|
private client;
|
|
5
5
|
constructor(client: ForumClient);
|
|
@@ -7,7 +7,7 @@ export declare class AuthResource {
|
|
|
7
7
|
login: string;
|
|
8
8
|
password: string;
|
|
9
9
|
}): Promise<LoginResponse>;
|
|
10
|
-
register(payload: import('../types').RegisterPayload): Promise<
|
|
10
|
+
register(payload: import('../types').RegisterPayload): Promise<RegisterResponse>;
|
|
11
11
|
me(): Promise<import('../types').User>;
|
|
12
12
|
forgotPassword(email: string): Promise<{
|
|
13
13
|
resetToken?: string;
|
package/dist/resources/Auth.js
CHANGED
|
@@ -16,10 +16,14 @@ class AuthResource {
|
|
|
16
16
|
return response;
|
|
17
17
|
}
|
|
18
18
|
async register(payload) {
|
|
19
|
-
|
|
19
|
+
const response = await this.client.request('/auth/register', {
|
|
20
20
|
method: 'POST',
|
|
21
21
|
body: JSON.stringify(payload),
|
|
22
22
|
});
|
|
23
|
+
if (response.token) {
|
|
24
|
+
this.client.setToken(response.token);
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
23
27
|
}
|
|
24
28
|
async me() {
|
|
25
29
|
return this.client.request('/auth/me', {
|
package/dist/types.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export interface PostListResponse {
|
|
|
113
113
|
export interface LoginResponse {
|
|
114
114
|
token: string;
|
|
115
115
|
}
|
|
116
|
+
export interface RegisterResponse {
|
|
117
|
+
user: User;
|
|
118
|
+
token: string;
|
|
119
|
+
}
|
|
116
120
|
export interface SecurityInfo {
|
|
117
121
|
userId: string;
|
|
118
122
|
username: string;
|
|
@@ -14,13 +14,15 @@ async function main() {
|
|
|
14
14
|
try {
|
|
15
15
|
// Example 1: User Registration
|
|
16
16
|
console.log('=== User Registration ===');
|
|
17
|
-
const
|
|
17
|
+
const { user, token } = await client.auth.register({
|
|
18
18
|
username: 'john_doe',
|
|
19
19
|
email: 'john@example.com',
|
|
20
20
|
password: 'securePassword123',
|
|
21
21
|
displayName: 'John Doe',
|
|
22
22
|
});
|
|
23
|
-
console.log('User registered:',
|
|
23
|
+
console.log('User registered:', user);
|
|
24
|
+
console.log('Auth token:', token);
|
|
25
|
+
// Note: Token is automatically set on the client
|
|
24
26
|
|
|
25
27
|
// Example 2: User Login
|
|
26
28
|
console.log('\n=== User Login ===');
|
|
@@ -29,9 +31,7 @@ async function main() {
|
|
|
29
31
|
password: 'securePassword123',
|
|
30
32
|
});
|
|
31
33
|
console.log('Login successful, token:', loginResponse.token);
|
|
32
|
-
|
|
33
|
-
// Store the token for authenticated requests
|
|
34
|
-
client.setToken(loginResponse.token);
|
|
34
|
+
// Note: Token is automatically set on the client
|
|
35
35
|
|
|
36
36
|
// Example 3: Get Current User
|
|
37
37
|
console.log('\n=== Get Current User ===');
|
package/package.json
CHANGED
package/src/resources/Auth.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
|
-
import { LoginResponse } from '../types';
|
|
2
|
+
import { LoginResponse, RegisterResponse } from '../types';
|
|
3
3
|
|
|
4
4
|
export class AuthResource {
|
|
5
5
|
private client: ForumClient;
|
|
@@ -21,11 +21,17 @@ export class AuthResource {
|
|
|
21
21
|
return response;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async register(payload: import('../types').RegisterPayload): Promise<
|
|
25
|
-
|
|
24
|
+
async register(payload: import('../types').RegisterPayload): Promise<RegisterResponse> {
|
|
25
|
+
const response = await this.client.request<RegisterResponse>('/auth/register', {
|
|
26
26
|
method: 'POST',
|
|
27
27
|
body: JSON.stringify(payload),
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
if (response.token) {
|
|
31
|
+
this.client.setToken(response.token);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return response;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
async me(): Promise<import('../types').User> {
|
package/src/types.ts
CHANGED