@@ -106,43 +106,46 @@ export { handle } from "./auth"
106
106
<Code.Express >
107
107
108
108
``` ts filename="./src/routes/auth.route.ts" {2, 11}
109
- import { ExpressAuth } from ' @auth/express'
110
- import Credentials from ' @auth/express/providers/credentials'
109
+ import { ExpressAuth } from " @auth/express"
110
+ import Credentials from " @auth/express/providers/credentials"
111
111
import express from " express"
112
112
// Your own logic for dealing with plaintext password strings; be careful!
113
113
import { saltAndHashPassword } from " @/utils/password"
114
114
115
115
const app = express ()
116
- app .use (" /auth/*" , ExpressAuth ({
117
- providers: [
118
- Credentials ({
119
- // You can specify which fields should be submitted, by adding keys to the `credentials` object.
120
- // e.g. domain, username, password, 2FA token, etc.
121
- credentials: {
122
- email: {},
123
- password: {},
124
- },
125
- authorize : async (credentials ) => {
126
- let user = null
116
+ app .use (
117
+ " /auth/*" ,
118
+ ExpressAuth ({
119
+ providers: [
120
+ Credentials ({
121
+ // You can specify which fields should be submitted, by adding keys to the `credentials` object.
122
+ // e.g. domain, username, password, 2FA token, etc.
123
+ credentials: {
124
+ email: {},
125
+ password: {},
126
+ },
127
+ authorize : async (credentials ) => {
128
+ let user = null
127
129
128
- // logic to salt and hash password
129
- const pwHash = saltAndHashPassword (credentials .password )
130
+ // logic to salt and hash password
131
+ const pwHash = saltAndHashPassword (credentials .password )
130
132
131
- // logic to verify if user exists
132
- user = await getUserFromDb (credentials .email , pwHash )
133
+ // logic to verify if user exists
134
+ user = await getUserFromDb (credentials .email , pwHash )
133
135
134
- if (! user ) {
135
- // No user found, so this is their first attempt to login
136
- // meaning this is also the place you could do registration
137
- throw new Error (" User not found." )
138
- }
136
+ if (! user ) {
137
+ // No user found, so this is their first attempt to login
138
+ // meaning this is also the place you could do registration
139
+ throw new Error (" User not found." )
140
+ }
139
141
140
- // return user object with the their profile data
141
- return user
142
- },
143
- }),
144
- ],
145
- }))
142
+ // return user object with the their profile data
143
+ return user
144
+ },
145
+ }),
146
+ ],
147
+ })
148
+ )
146
149
```
147
150
148
151
</Code.Express >
0 commit comments