@@ -133,12 +133,12 @@ The Express package runs server-side and therefore it doesn't make sense to crea
133
133
134
134
To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:
135
135
136
- ``` js filename="src/routes/auth.js"
137
- const express = require (" express" )
136
+ ``` ts filename="src/routes/auth.ts"
137
+ import express , { Request , Response } from " express"
138
+ import { signIn } from " ../auth"
138
139
const router = express .Router ()
139
- const { signIn } = require (" ../auth" )
140
140
141
- router .post (" /auth/signin" , async (req , res ) => {
141
+ router .post (" /auth/signin" , async (req : Request , res : Response ) => {
142
142
try {
143
143
await signIn (req , res )
144
144
res .redirect (" /dashboard" )
@@ -147,17 +147,17 @@ router.post("/auth/signin", async (req, res) => {
147
147
}
148
148
})
149
149
150
- module . exports = router
150
+ export { router }
151
151
```
152
152
153
153
To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:
154
154
155
- ``` js filename="src/routes/auth.js"
156
- const express = require (" express" )
155
+ ``` ts filename="src/routes/auth.ts"
156
+ import express , { Request , Response } from " express"
157
+ import { signOut } from " ../auth"
157
158
const router = express .Router ()
158
- const { signOut } = require (" ../auth" )
159
159
160
- router .post (" /auth/signout" , async (req , res ) => {
160
+ router .post (" /auth/signout" , async (req : Request , res : Response ) => {
161
161
try {
162
162
await signOut (req , res )
163
163
res .redirect (" /" )
@@ -166,7 +166,7 @@ router.post("/auth/signout", async (req, res) => {
166
166
}
167
167
})
168
168
169
- module . exports = router
169
+ export { router }
170
170
```
171
171
172
172
</Code.Express >
@@ -266,6 +266,24 @@ export default component$(() => {
266
266
```
267
267
268
268
</Code.Svelte >
269
+ <Code.Express >
270
+ ``` ts filename="src/routes/auth.ts"
271
+ import express , { Request , Response } from " express" ;
272
+ import { signOut } from " ../auth" ;
273
+ const router = express .Router ()
274
+
275
+ router .post (" /auth/signout" , async (req : Request , res : Response ) => {
276
+ try {
277
+ await signOut (req , res )
278
+ res .redirect (" /" )
279
+ } catch (error ) {
280
+ res .status (500 ).send (" Sign out failed" )
281
+ }
282
+ })
283
+
284
+ export { router }
285
+ ```
286
+ </Code.Express >
269
287
</Code >
270
288
271
289
### Signout
@@ -392,12 +410,12 @@ The Express package runs server-side and therefore it doesn't make sense to crea
392
410
393
411
To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:
394
412
395
- ``` js filename="src/routes/auth.js"
396
- const express = require (" express" )
413
+ ``` ts filename="src/routes/auth.ts"
414
+ import express , { Request , Response } from " express"
415
+ import { signIn } from " ../auth"
397
416
const router = express .Router ()
398
- const { signIn } = require (" ../auth" )
399
417
400
- router .post (" /auth/signin" , async (req , res ) => {
418
+ router .post (" /auth/signin" , async (req : Request , res : Response ) => {
401
419
try {
402
420
await signIn (req , res )
403
421
res .redirect (" /dashboard" )
@@ -406,17 +424,17 @@ router.post("/auth/signin", async (req, res) => {
406
424
}
407
425
})
408
426
409
- module . exports = router
427
+ export { router }
410
428
```
411
429
412
430
To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:
413
431
414
- ``` js filename="src/routes/auth.js"
415
- const express = require (" express" )
432
+ ``` ts filename="src/routes/auth.ts"
433
+ import express , { Request , Response } from " express"
434
+ import { signOut } from " ../auth"
416
435
const router = express .Router ()
417
- const { signOut } = require (" ../auth" )
418
436
419
- router .post (" /auth/signout" , async (req , res ) => {
437
+ router .post (" /auth/signout" , async (req : Request , res : Response ) => {
420
438
try {
421
439
await signOut (req , res )
422
440
res .redirect (" /" )
@@ -425,7 +443,7 @@ router.post("/auth/signout", async (req, res) => {
425
443
}
426
444
})
427
445
428
- module . exports = router
446
+ export { router }
429
447
```
430
448
431
449
</Code.Express >
0 commit comments