-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
45 lines (44 loc) · 1.17 KB
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { SignInCredentials } from "@/app/types";
import axios from "axios";
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
const authConfig = {
providers: [
CredentialsProvider({
type: "credentials",
credentials: {},
async authorize(credentials, request) {
const { email, password } = credentials as SignInCredentials;
try {
const response = await axios.post(
"http://localhost:3000/api/users/signin",
{ email, password }
);
if(response.data.error) return null
return {id: response.data.user.id,...response.data.user} ;
} catch (error: any) {
throw new Error(error);
}
},
}),
],
callbacks:{
async jwt(params:any){
if(params.user){
params.token.user = params.user
}
return params.token
},
async session(params:any){
const user = params.token.user
if(user){
params.session.user = {...params.session.user,...user}
}
return params.session
}
}
};
export const {
handlers: { GET, POST },
auth,
} = NextAuth(authConfig);