@@ -40,9 +40,9 @@ The SDK automatically detects and handles OAuth callback parameters when initial
4040
4141** How it works:**
42421 . User calls ` signInWithOAuth() ` and is redirected to OAuth provider
43- 2 . After authentication, provider redirects back to your app with tokens in URL
44- 3 . SDK automatically detects these parameters on initialization
45- 4 . Session is saved and URL is cleaned - no manual handling needed!
43+ 2 . After authentication, InsForge redirects back to your app with an ` insforge_code ` in the URL
44+ 3 . SDK automatically exchanges that code for a session on initialization
45+ 4 . Session is saved and the URL is cleaned - no manual handling needed
4646
4747** Example:**
4848``` javascript
@@ -52,11 +52,12 @@ const insforge = createClient({
5252});
5353
5454// If the URL contains OAuth callback parameters like:
55- // ?access_token=xxx&user_id=yyy&email=user@example.com&name=John
55+ // ?insforge_code=...
5656// The SDK will:
57+ // - Exchange the code for a session
5758// - Save the session in memory
5859// - Set the auth token for API calls
59- // - Clean the URL (remove sensitive parameters)
60+ // - Clean the URL
6061
6162// You can then immediately use authenticated methods:
6263const { data } = await insforge .auth .getCurrentUser ();
@@ -69,13 +70,23 @@ const { data } = await insforge.auth.getCurrentUser();
6970await insforge .auth .signUp ({
7071 email: ' user@example.com' ,
7172 password: ' password123' ,
72- name: ' John Doe' // optional
73+ name: ' John Doe' , // optional
74+ redirectTo: ' http://localhost:3000/sign-in' // optional, recommended for link-based verification
7375})
7476// Response: { data: { user, accessToken }, error }
7577// user: { id, email, name, emailVerified, createdAt, updatedAt }
7678// accessToken: JWT token string
7779```
7880
81+ If the backend uses link-based email verification, the emailed link opens:
82+
83+ ``` text
84+ GET /api/auth/email/verify-link?token=...
85+ ```
86+
87+ InsForge validates the token first, then redirects the browser to your ` redirectTo ` URL.
88+ Recommended: use your sign-in page as ` redirectTo ` , then show a success message and ask the user to sign in with email and password.
89+
7990### ` signInWithPassword() `
8091``` javascript
8192await insforge .auth .signInWithPassword ({
@@ -99,9 +110,10 @@ await insforge.auth.signInWithOAuth({
99110
100111// AUTOMATIC OAuth Callback Detection (v0.0.14+):
101112// When users are redirected back from OAuth provider, the SDK automatically:
102- // 1. Detects OAuth parameters (access_token, user_id, email, name) in URL
103- // 2. Saves the session in memory
104- // 3. Cleans the URL of sensitive parameters
113+ // 1. Detects insforge_code in the URL
114+ // 2. Exchanges the code for a session
115+ // 3. Saves the session in memory
116+ // 4. Cleans the URL
105117// No manual handling needed - just initialize the client!
106118```
107119
@@ -115,12 +127,15 @@ await insforge.auth.signOut()
115127### ` getCurrentUser() `
116128``` javascript
117129await insforge .auth .getCurrentUser ()
118- // Response: { data: { user, profile }, error }
119- // user: { id, email, role } // Auth info from API
120- // profile: { id, nickname, avatar_url, bio, birthday, ... } // Profile from users table
130+ // Response: { data: { user }, error }
131+ // user: { id, email, emailVerified, providers, createdAt, updatedAt, profile, metadata }
121132// Returns null if not authenticated
122133```
123134
135+ For browser apps, call ` getCurrentUser() ` during startup. The SDK will use the httpOnly refresh cookie automatically when it can refresh the session.
136+
137+ For ` isServerMode: true ` , call ` refreshSession({ refreshToken }) ` explicitly when you need to refresh an expired access token.
138+
124139### ` getProfile() `
125140``` javascript
126141await insforge .auth .getProfile (userId)
@@ -149,6 +164,64 @@ await insforge.auth.getPublicAuthConfig()
149164// This is a public endpoint that doesn't require authentication
150165```
151166
167+ ### ` resendVerificationEmail() `
168+ ``` javascript
169+ await insforge .auth .resendVerificationEmail ({
170+ email: ' user@example.com' ,
171+ redirectTo: ' http://localhost:3000/sign-in' // optional, recommended for link-based verification
172+ })
173+ // Response: { data: { success, message }, error }
174+ ```
175+
176+ ### ` verifyEmail() `
177+ ``` javascript
178+ await insforge .auth .verifyEmail ({
179+ email: ' user@example.com' ,
180+ otp: ' 123456'
181+ })
182+ // Response: { data: { user, accessToken, csrfToken?, refreshToken? }, error }
183+ // POST /api/auth/email/verify is code-only
184+ // Browser link verification uses GET /api/auth/email/verify-link
185+ // Verification redirect params:
186+ // - insforge_status=success|error
187+ // - insforge_type=verify_email
188+ // - insforge_error (only on error)
189+ ```
190+
191+ ### ` sendResetPasswordEmail() `
192+ ``` javascript
193+ await insforge .auth .sendResetPasswordEmail ({
194+ email: ' user@example.com' ,
195+ redirectTo: ' http://localhost:3000/reset-password' // optional, recommended for link-based reset
196+ })
197+ // Response: { data: { success, message }, error }
198+ ```
199+
200+ ### ` exchangeResetPasswordToken() `
201+ ``` javascript
202+ await insforge .auth .exchangeResetPasswordToken ({
203+ email: ' user@example.com' ,
204+ code: ' 123456'
205+ })
206+ // Response: { data: { token, expiresAt }, error }
207+ ```
208+
209+ ### ` resetPassword() `
210+ ``` javascript
211+ await insforge .auth .resetPassword ({
212+ newPassword: ' newSecurePassword123' ,
213+ otp: ' reset-token'
214+ })
215+ // Response: { data: { message }, error }
216+ // Browser reset links use GET /api/auth/email/reset-password-link first,
217+ // then your app submits the new password with POST /api/auth/email/reset-password.
218+ // Reset redirect params:
219+ // - token (present only when ready)
220+ // - insforge_status=ready|error
221+ // - insforge_type=reset_password
222+ // - insforge_error (only on error)
223+ ```
224+
152225## Error Handling
153226
154227### Auth/Storage/AI Errors (InsForgeError)
0 commit comments