route handlers for account/main
This commit is contained in:
@@ -75,14 +75,6 @@ const authOptions: NextAuthOptions = {
|
||||
throw new Error('Все поля обязательны для заполнения')
|
||||
}
|
||||
|
||||
// console.log('Registration data:', {
|
||||
// email: credentials.email,
|
||||
// name: credentials.name,
|
||||
// surname: credentials.surname,
|
||||
// phone_number: credentials.phone_number,
|
||||
// privacy_accepted: credentials.privacy_accepted,
|
||||
// })
|
||||
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/register/clients/`,
|
||||
{
|
||||
@@ -125,54 +117,7 @@ const authOptions: NextAuthOptions = {
|
||||
},
|
||||
}),
|
||||
|
||||
//регистрация менеджера
|
||||
CredentialsProvider({
|
||||
id: 'register-credentials-manager',
|
||||
name: 'RegisterManager',
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
username: { label: 'Username', type: 'text' },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/register/business/`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: credentials?.email,
|
||||
password: credentials?.password,
|
||||
username: credentials?.username,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text()
|
||||
console.error('Backend error response:', text)
|
||||
throw new Error('Registration failed: ' + text)
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
|
||||
return {
|
||||
id: data.user.id.toString(),
|
||||
email: data.user.email,
|
||||
name: data.user.firstName,
|
||||
accessToken: data.access,
|
||||
refreshToken: data.refresh,
|
||||
userType: data.user.userType || 'manager',
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
//логин обычный
|
||||
//логин
|
||||
CredentialsProvider({
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
@@ -212,50 +157,6 @@ const authOptions: NextAuthOptions = {
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
//логин для менеджеров
|
||||
CredentialsProvider({
|
||||
id: 'login-credentials-manager',
|
||||
name: 'Credentials',
|
||||
credentials: {
|
||||
email: { label: 'Email', type: 'email' },
|
||||
password: { label: 'Password', type: 'password' },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${process.env.BACKEND_URL}/auth/login/business/`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
email: credentials?.email,
|
||||
password: credentials?.password,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
const data = await res.json()
|
||||
// console.log('Business login response:', data)
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || 'Authentication failed')
|
||||
}
|
||||
|
||||
return {
|
||||
id: data.user.id.toString(),
|
||||
email: data.user.email || `${data.user.phone_number}@example.com`,
|
||||
name: data.user.username || data.user.title,
|
||||
accessToken: data.access,
|
||||
refreshToken: data.refresh,
|
||||
userType: data.user.userType || 'manager',
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login error:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
async jwt({ token, user, account }) {
|
||||
|
||||
Reference in New Issue
Block a user