Skip to content

Commit

Permalink
chore(docs): Update Express sign-in and sign-out examples with TypeSc…
Browse files Browse the repository at this point in the history
…ript (#12467)

* docs: add Express sign-in and sign-out route examples to session management

* chore(docs): update Express sign-in and sign-out examples to use TypeScript and improve error handling

* chore(docs): update sign-out example in session management to redirect to home

* chore(docs): update sign-out example in session management to use correct import for signOut
  • Loading branch information
kingdavidHub authored Jan 7, 2025
1 parent 7772375 commit fc7c562
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions docs/pages/getting-started/session-management/login.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ The Express package runs server-side and therefore it doesn't make sense to crea

To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:

```js filename="src/routes/auth.js"
const express = require("express")
```ts filename="src/routes/auth.ts"
import express, { Request, Response } from "express"
import { signIn } from "../auth"
const router = express.Router()
const { signIn } = require("../auth")

router.post("/auth/signin", async (req, res) => {
router.post("/auth/signin", async (req: Request, res: Response) => {
try {
await signIn(req, res)
res.redirect("/dashboard")
Expand All @@ -147,17 +147,17 @@ router.post("/auth/signin", async (req, res) => {
}
})

module.exports = router
export { router }
```

To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:

```js filename="src/routes/auth.js"
const express = require("express")
```ts filename="src/routes/auth.ts"
import express, { Request, Response } from "express"
import { signOut } from "../auth"
const router = express.Router()
const { signOut } = require("../auth")

router.post("/auth/signout", async (req, res) => {
router.post("/auth/signout", async (req: Request, res: Response) => {
try {
await signOut(req, res)
res.redirect("/")
Expand All @@ -166,7 +166,7 @@ router.post("/auth/signout", async (req, res) => {
}
})

module.exports = router
export { router }
```

</Code.Express>
Expand Down Expand Up @@ -266,6 +266,24 @@ export default component$(() => {
```

</Code.Svelte>
<Code.Express>
```ts filename="src/routes/auth.ts"
import express, { Request, Response } from "express";
import { signOut } from "../auth";
const router = express.Router()

router.post("/auth/signout", async (req: Request, res: Response) => {
try {
await signOut(req, res)
res.redirect("/")
} catch (error) {
res.status(500).send("Sign out failed")
}
})

export { router }
```
</Code.Express>
</Code>

### Signout
Expand Down Expand Up @@ -392,12 +410,12 @@ The Express package runs server-side and therefore it doesn't make sense to crea

To sign in users with Express, you can create a route that handles the sign-in logic. Here is an example:

```js filename="src/routes/auth.js"
const express = require("express")
```ts filename="src/routes/auth.ts"
import express, { Request, Response } from "express"
import { signIn } from "../auth"
const router = express.Router()
const { signIn } = require("../auth")

router.post("/auth/signin", async (req, res) => {
router.post("/auth/signin", async (req: Request, res: Response) => {
try {
await signIn(req, res)
res.redirect("/dashboard")
Expand All @@ -406,17 +424,17 @@ router.post("/auth/signin", async (req, res) => {
}
})

module.exports = router
export { router }
```

To sign out users with Express, you can create a route that handles the sign-out logic. Here is an example:

```js filename="src/routes/auth.js"
const express = require("express")
```ts filename="src/routes/auth.ts"
import express, { Request, Response } from "express"
import { signOut } from "../auth"
const router = express.Router()
const { signOut } = require("../auth")

router.post("/auth/signout", async (req, res) => {
router.post("/auth/signout", async (req: Request, res: Response) => {
try {
await signOut(req, res)
res.redirect("/")
Expand All @@ -425,7 +443,7 @@ router.post("/auth/signout", async (req, res) => {
}
})

module.exports = router
export { router }
```

</Code.Express>
Expand Down

0 comments on commit fc7c562

Please sign in to comment.