@taruvi/sdk 1.4.8-beta.1 → 1.4.9

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": "@taruvi/sdk",
3
- "version": "1.4.8-beta.1",
3
+ "version": "1.4.9",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -1,6 +1,7 @@
1
1
  import type { Client } from "../../client.js";
2
2
  import type { TaruviResponse } from "../../types.js";
3
3
  import type { UserData } from "../users/types.js";
4
+ import { AuthRoutes } from "../../lib-internal/routes/AuthRoutes.js";
4
5
  import { UserRoutes } from "../../lib-internal/routes/UserRoutes.js";
5
6
 
6
7
  /**
@@ -94,12 +95,33 @@ export class Auth {
94
95
  }
95
96
 
96
97
  /**
97
- * Check if user is authenticated (has session token)
98
+ * Check if a session token exists locally (does not validate with server)
98
99
  */
99
- isUserAuthenticated(): boolean {
100
+ hasToken(): boolean {
100
101
  return this.client.tokenClient.isAuthenticated()
101
102
  }
102
103
 
104
+ /**
105
+ * Check if user is authenticated by validating session with the server
106
+ */
107
+ async isUserAuthenticated(): Promise<boolean> {
108
+ if (!this.hasToken()) return false
109
+ try {
110
+ await this.validateSession()
111
+ return true
112
+ } catch {
113
+ return false
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Validate current session token with auth session endpoint.
119
+ * HttpClient injects X-Session-Token automatically.
120
+ */
121
+ async validateSession(): Promise<void> {
122
+ await this.client.httpClient.get(AuthRoutes.session())
123
+ }
124
+
103
125
  /**
104
126
  * Get the current session token
105
127
  */
@@ -112,7 +134,7 @@ export class Auth {
112
134
  * @returns Promise with user data or null if not authenticated
113
135
  */
114
136
  async getCurrentUser(): Promise<TaruviResponse<UserData> | null> {
115
- if (!this.isUserAuthenticated()) {
137
+ if (!this.hasToken()) {
116
138
  return null
117
139
  }
118
140
 
@@ -25,7 +25,6 @@ export class HttpClient {
25
25
 
26
26
  private setupInterceptors(): void {
27
27
  // Request interceptor: attach session token
28
- console.log("test")
29
28
  this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
30
29
  const isFormData = config.data instanceof FormData
31
30
  if (!isFormData) {
@@ -0,0 +1,3 @@
1
+ export const AuthRoutes = {
2
+ session: () => "_allauth/app/v1/auth/session"
3
+ } as const