File tree Expand file tree Collapse file tree 4 files changed +22
-16
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +22
-16
lines changed
Original file line number Diff line number Diff line change @@ -72,8 +72,8 @@ export async function registerWithEmail(
72
72
}
73
73
}
74
74
75
- export async function loginWithEmail ( email : string , password : string ) {
76
- const user = await $fetch < IUser > ( '/api/auth/login' , { method : 'POST' , body : { email : email , password : password } } )
75
+ export async function loginWithEmail ( usernameOrEmail : string , password : string ) {
76
+ const user = await $fetch < IUser > ( '/api/auth/login' , { method : 'POST' , body : { usernameOrEmail : usernameOrEmail , password : password } } )
77
77
useState ( 'user' ) . value = user
78
78
await useRouter ( ) . push ( '/dashboard' )
79
79
}
Original file line number Diff line number Diff line change 2
2
import { ref } from " @vue/reactivity" ;
3
3
import {loginWithEmail } from " ~/composables/useAuth" ;
4
4
5
- const email = ref (null )
5
+ const usernameOrEmail = ref (null )
6
6
const password = ref (null )
7
7
const hasError = ref (null )
8
8
const errorMessage = ref (null )
@@ -13,7 +13,7 @@ definePageMeta({
13
13
})
14
14
15
15
const postLoginForm = async function () {
16
- await loginWithEmail (email .value , password .value )
16
+ await loginWithEmail (usernameOrEmail .value , password .value )
17
17
}
18
18
</script >
19
19
@@ -50,10 +50,10 @@ const postLoginForm = async function () {
50
50
<input type =" hidden" name =" remember" value =" true" >
51
51
<div class =" rounded-md shadow-sm -space-y-px mb-1" >
52
52
<div >
53
- <label for =" email-address" class =" sr-only" >Email address </label >
54
- <input v-model =" email " id =" email-address" name =" email" type =" email" autocomplete =" email" required
53
+ <label for =" email-address" class =" sr-only" >Username or Email </label >
54
+ <input v-model =" usernameOrEmail " id =" email-address" name =" email" type =" email" autocomplete =" email" required
55
55
class =" appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
56
- placeholder =" Email address " >
56
+ placeholder =" Username or Email " >
57
57
</div >
58
58
</div >
59
59
<div >
Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ import { makeSession } from '~~/server/services/sessionService';
6
6
7
7
export default async ( event : CompatibilityEvent ) => {
8
8
const body = await readBody ( event )
9
- const email : string = body . email
9
+ const usernameOrEmail : string = body . usernameOrEmail
10
10
const password : string = body . password
11
- const user = await getUserByEmail ( email )
11
+
12
+ const user = await getUserByEmail ( usernameOrEmail )
12
13
13
14
if ( user === null ) {
14
15
sendError ( event , createError ( { statusCode : 401 , statusMessage : 'Unauthenticated' } ) )
Original file line number Diff line number Diff line change 1
1
import prisma from "~/server/database/client" ;
2
- import { IUser } from '~/types/IUser' ;
2
+ import { IUser } from '~/types/IUser' ;
3
3
import { ISubscription } from "~~/types/ISubscription" ;
4
4
5
- export async function getUserByEmail ( email : string ) : Promise < IUser > {
6
- return await prisma . user . findUnique ( {
5
+ export async function getUserByEmail ( emailOrEmail : string ) : Promise < IUser > {
6
+ return await prisma . user . findFirst ( {
7
7
where : {
8
- email : email ,
8
+ OR :
9
+ [
10
+ { email : emailOrEmail } ,
11
+ { username : emailOrEmail } ,
12
+ ]
9
13
} ,
10
14
select : {
11
15
id : true ,
12
16
username : true ,
17
+ password : true
13
18
} ,
14
19
} )
15
20
}
@@ -78,7 +83,7 @@ export async function getSubscriptionById(stripeId: string): Promise<ISubscripti
78
83
79
84
export async function updateStripeCustomerId ( data : IUser ) {
80
85
return await prisma . user . update ( {
81
- where : { email : data . email } ,
86
+ where : { email : data . email } ,
82
87
data : {
83
88
stripeCustomerId : data . stripeCustomerId ,
84
89
}
@@ -87,8 +92,8 @@ export async function updateStripeCustomerId(data: IUser) {
87
92
88
93
export async function createOrUpdateSubscription ( data : ISubscription ) {
89
94
return await prisma . subscription . upsert ( {
90
- where :{
91
- stripeId : data . stripeId
95
+ where : {
96
+ stripeId : data . stripeId
92
97
} ,
93
98
create : {
94
99
userId : data . userId ,
You can’t perform that action at this time.
0 commit comments