Skip to content

Commit

Permalink
chore(docs): pnpm format (#11120)
Browse files Browse the repository at this point in the history
chore: `pnpm format`
  • Loading branch information
k-taro56 authored Jun 13, 2024
1 parent 24b0e66 commit ec93976
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions docs/pages/getting-started/authentication/credentials.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,43 +106,46 @@ export { handle } from "./auth"
<Code.Express>

```ts filename="./src/routes/auth.route.ts" {2, 11}
import { ExpressAuth } from '@auth/express'
import Credentials from '@auth/express/providers/credentials'
import { ExpressAuth } from "@auth/express"
import Credentials from "@auth/express/providers/credentials"
import express from "express"
// Your own logic for dealing with plaintext password strings; be careful!
import { saltAndHashPassword } from "@/utils/password"

const app = express()
app.use("/auth/*", ExpressAuth({
providers: [
Credentials({
// You can specify which fields should be submitted, by adding keys to the `credentials` object.
// e.g. domain, username, password, 2FA token, etc.
credentials: {
email: {},
password: {},
},
authorize: async (credentials) => {
let user = null
app.use(
"/auth/*",
ExpressAuth({
providers: [
Credentials({
// You can specify which fields should be submitted, by adding keys to the `credentials` object.
// e.g. domain, username, password, 2FA token, etc.
credentials: {
email: {},
password: {},
},
authorize: async (credentials) => {
let user = null

// logic to salt and hash password
const pwHash = saltAndHashPassword(credentials.password)
// logic to salt and hash password
const pwHash = saltAndHashPassword(credentials.password)

// logic to verify if user exists
user = await getUserFromDb(credentials.email, pwHash)
// logic to verify if user exists
user = await getUserFromDb(credentials.email, pwHash)

if (!user) {
// No user found, so this is their first attempt to login
// meaning this is also the place you could do registration
throw new Error("User not found.")
}
if (!user) {
// No user found, so this is their first attempt to login
// meaning this is also the place you could do registration
throw new Error("User not found.")
}

// return user object with the their profile data
return user
},
}),
],
}))
// return user object with the their profile data
return user
},
}),
],
})
)
```

</Code.Express>
Expand Down

0 comments on commit ec93976

Please sign in to comment.