Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Update Express sign-in and sign-out examples with TypeScript #12467

Merged
merged 6 commits into from
Jan 7, 2025
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
Loading