Skip to content

Commit 0820bb5

Browse files
authored
chore(docs): add Express sign-in and sign-out route examples to session management (#12450)
docs: add Express sign-in and sign-out route examples to session management
1 parent 48d775a commit 0820bb5

File tree

1 file changed

+77
-0
lines changed
  • docs/pages/getting-started/session-management

1 file changed

+77
-0
lines changed

docs/pages/getting-started/session-management/login.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,47 @@ Just like in other frameworks, you can also pass a provider to the `signIn` func
129129
</Code.Svelte>
130130
<Code.Express>
131131

132+
132133
The Express package runs server-side and therefore it doesn't make sense to create a "SignIn button component". However, to signin or signout with Express, send a request to the appropriate [REST API Endpoints](/reference/core/types#authaction) from your client (i.e. `/auth/signin`, `/auth/signout`, etc.).
133134

135+
To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:
136+
137+
```js filename="src/routes/auth.js"
138+
const express = require("express")
139+
const router = express.Router()
140+
const { signIn } = require("../auth")
141+
142+
router.post("/auth/signin", async (req, res) => {
143+
try {
144+
await signIn(req, res)
145+
res.redirect("/dashboard")
146+
} catch (error) {
147+
res.status(500).send("Sign in failed")
148+
}
149+
})
150+
151+
module.exports = router
152+
```
153+
154+
To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:
155+
156+
```js filename="src/routes/auth.js"
157+
const express = require("express")
158+
const router = express.Router()
159+
const { signOut } = require("../auth")
160+
161+
router.post("/auth/signout", async (req, res) => {
162+
try {
163+
await signOut(req, res)
164+
res.redirect("/")
165+
} catch (error) {
166+
res.status(500).send("Sign out failed")
167+
}
168+
})
169+
170+
module.exports = router
171+
```
172+
134173
</Code.Express>
135174
</Code>
136175

@@ -352,6 +391,44 @@ Client-side is a bit simpler as we just need to import a button `on:click` handl
352391

353392
The Express package runs server-side and therefore it doesn't make sense to create a "SignIn button component". However, to signin or signout with Express, send a request to the appropriate [REST API Endpoints](/reference/core/types#authaction) from your client (i.e. `/auth/signin`, `/auth/signout`, etc.).
354393

394+
To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:
395+
396+
```js filename="src/routes/auth.js"
397+
const express = require("express")
398+
const router = express.Router()
399+
const { signIn } = require("../auth")
400+
401+
router.post("/auth/signin", async (req, res) => {
402+
try {
403+
await signIn(req, res)
404+
res.redirect("/dashboard")
405+
} catch (error) {
406+
res.status(500).send("Sign in failed")
407+
}
408+
})
409+
410+
module.exports = router
411+
```
412+
413+
To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:
414+
415+
```js filename="src/routes/auth.js"
416+
const express = require("express")
417+
const router = express.Router()
418+
const { signOut } = require("../auth")
419+
420+
router.post("/auth/signout", async (req, res) => {
421+
try {
422+
await signOut(req, res)
423+
res.redirect("/")
424+
} catch (error) {
425+
res.status(500).send("Sign out failed")
426+
}
427+
})
428+
429+
module.exports = router
430+
```
431+
355432
</Code.Express>
356433
</Code>
357434

0 commit comments

Comments
 (0)