Skip to content

Commit 93cf005

Browse files
Merge pull request #125 from authsmith/v0.7.3
V0.7.3
2 parents a26158c + 17228b5 commit 93cf005

22 files changed

+89
-65
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "payload-auth-plugin",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"type": "module",
55
"sideEffects": false,
66
"author": "Sourab Pramanik<shubpramanik241@gmail.com>",

src/core/errors/apiErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class InternalServerError extends AuthAPIError {
100100
export class MissingOrInvalidVerification extends AuthAPIError {
101101
constructor() {
102102
super(
103-
"Verifcation failed. Missing or invalid verification code.",
103+
"Verification failed. Missing or invalid verification code.",
104104
ErrorKind.BadRequest,
105105
)
106106
}

src/core/protocols/email.ts

Whitespace-only changes.

src/core/protocols/oauth/oauth_authentication.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export async function OAuthAuthentication(
3131
picture?: string | undefined
3232
},
3333
): Promise<Response> {
34-
const { email, sub, name, scope, issuer, picture } = account
34+
const { email: _email, sub, name, scope, issuer, picture } = account
3535
const { payload } = request
36+
37+
const email = _email.toLowerCase()
38+
3639
const userRecords = await payload.find({
3740
collection: collections.usersCollection,
3841
where: {

src/core/protocols/password.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1+
import { parseCookies, type PayloadRequest } from "payload"
12
import {
2-
BasePayload,
3-
getCookieExpiration,
4-
parseCookies,
5-
type PayloadRequest,
6-
} from "payload"
7-
import {
8-
AuthenticationFailed,
93
EmailAlreadyExistError,
104
InvalidCredentials,
115
InvalidRequestBodyError,
@@ -16,14 +10,10 @@ import {
1610
import { hashPassword, verifyPassword } from "../utils/password.js"
1711
import { SuccessKind } from "../../types.js"
1812
import { ephemeralCode, verifyEphemeralCode } from "../utils/hash.js"
19-
import {
20-
APP_COOKIE_SUFFIX,
21-
EPHEMERAL_CODE_COOKIE_NAME,
22-
} from "../../constants.js"
13+
import { APP_COOKIE_SUFFIX } from "../../constants.js"
2314
import {
2415
createSessionCookies,
2516
invalidateOAuthCookies,
26-
invalidateSessionCookies,
2717
verifySessionCookie,
2818
} from "../utils/cookies.js"
2919

@@ -72,11 +62,13 @@ export const PasswordSignin = async (
7262
return new InvalidRequestBodyError()
7363
}
7464

65+
const email = body.email.toLowerCase()
66+
7567
const { payload } = request
7668
const { docs } = await payload.find({
7769
collection: internal.usersCollectionSlug,
7870
where: {
79-
email: { equals: body.email },
71+
email: { equals: email },
8072
},
8173
limit: 1,
8274
})
@@ -104,7 +96,7 @@ export const PasswordSignin = async (
10496
: `__${pluginType}-${APP_COOKIE_SUFFIX}`
10597
const signinFields = {
10698
id: userRecord.id,
107-
email: body.email,
99+
email,
108100
collection: internal.usersCollectionSlug,
109101
}
110102
return await redirectWithSession(
@@ -140,11 +132,12 @@ export const PasswordSignup = async (
140132
return new InvalidRequestBodyError()
141133
}
142134

135+
const email = body.email.toLowerCase()
143136
const { payload } = request
144137
const { docs } = await payload.find({
145138
collection: internal.usersCollectionSlug,
146139
where: {
147-
email: { equals: body.email },
140+
email: { equals: email },
148141
},
149142
limit: 1,
150143
})
@@ -162,7 +155,7 @@ export const PasswordSignup = async (
162155
const userRecord = await payload.create({
163156
collection: internal.usersCollectionSlug,
164157
data: {
165-
email: body.email,
158+
email,
166159
hashedPassword: hashedPassword,
167160
hashIterations: iterations,
168161
hashSalt,
@@ -176,7 +169,7 @@ export const PasswordSignup = async (
176169
: `__${pluginType}-${APP_COOKIE_SUFFIX}`
177170
const signinFields = {
178171
id: userRecord.id,
179-
email: body.email,
172+
email,
180173
collection: internal.usersCollectionSlug,
181174
}
182175
return await redirectWithSession(
@@ -217,11 +210,11 @@ export const ForgotPasswordInit = async (
217210
if (!body?.email) {
218211
return new InvalidRequestBodyError()
219212
}
220-
213+
const email = body.email.toLowerCase()
221214
const { docs } = await payload.find({
222215
collection: internal.usersCollectionSlug,
223216
where: {
224-
email: { equals: body.email },
217+
email: { equals: email },
225218
},
226219
limit: 1,
227220
})
@@ -232,7 +225,7 @@ export const ForgotPasswordInit = async (
232225
const { code, hash } = await ephemeralCode(6, payload.secret)
233226

234227
await payload.sendEmail({
235-
to: body.email,
228+
to: email,
236229
subject: "Password recovery",
237230
html: await emailTemplate({
238231
verificationCode: code,
@@ -375,10 +368,12 @@ export const ResetPassword = async (
375368
return new InvalidRequestBodyError()
376369
}
377370

371+
const email = body.email.toLowerCase()
372+
378373
const { docs } = await payload.find({
379374
collection: internal.usersCollectionSlug,
380375
where: {
381-
email: { equals: body.email },
376+
email: { equals: email },
382377
},
383378
limit: 1,
384379
})

src/providers/oauth2/apple.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import type {
77

88
type AppleAuthConfig = OAuthBaseProviderConfig
99

10-
const algorithm = "oauth2"
11-
1210
const authorization_server: AuthorizationServer = {
1311
issuer: "https://appleid.apple.com",
1412
authorization_endpoint: "https://appleid.apple.com/auth/authorize",
@@ -47,13 +45,15 @@ const authorization_server: AuthorizationServer = {
4745
*/
4846

4947
function AppleOAuth2Provider(config: AppleAuthConfig): OAuth2ProviderConfig {
48+
const { overrideScope, ...restConfig } = config
49+
5050
return {
51-
...config,
51+
...restConfig,
5252
id: "apple",
53-
scope: "name email",
53+
scope: overrideScope ?? "name email",
5454
authorization_server,
5555
name: "Apple",
56-
algorithm,
56+
algorithm: "oauth2",
5757
params: {
5858
...config.params,
5959
response_mode: "form_post",

src/providers/oauth2/atlassian.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ type AtlassianAuthConfig = OAuthBaseProviderConfig
4949
function AtlassianAuthProvider(
5050
config: AtlassianAuthConfig,
5151
): OAuth2ProviderConfig {
52+
const { overrideScope, ...restConfig } = config
5253
return {
53-
...config,
54+
...restConfig,
5455
id: "atlassian",
5556
authorization_server,
5657
name: "Atlassian",
5758
algorithm,
58-
scope: "read:me read:account",
59+
scope: overrideScope ?? "read:me read:account",
5960
kind: "oauth",
6061
profile: (profile): AccountInfo => {
6162
return {

src/providers/oauth2/auth0.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface Auth0AuthConfig extends OAuthBaseProviderConfig {
4141
*/
4242

4343
function Auth0AuthProvider(config: Auth0AuthConfig): OAuth2ProviderConfig {
44-
const { domain, ...restConfig } = config
44+
const { domain, overrideScope, ...restConfig } = config
4545
const authorization_server: oauth.AuthorizationServer = {
4646
issuer: `https://${domain}/`,
4747
authorization_endpoint: `https://${domain}/authorize`,
@@ -52,7 +52,7 @@ function Auth0AuthProvider(config: Auth0AuthConfig): OAuth2ProviderConfig {
5252
return {
5353
...restConfig,
5454
id: "auth0",
55-
scope: "openid email profile",
55+
scope: overrideScope ?? "openid email profile",
5656
authorization_server,
5757
name: "Auth0",
5858
algorithm: "oauth2",

src/providers/oauth2/discord.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ type DiscordAuthConfig = OAuthBaseProviderConfig
4242
*/
4343

4444
function DiscordAuthProvider(config: DiscordAuthConfig): OAuth2ProviderConfig {
45+
const { overrideScope, ...restConfig } = config
46+
4547
return {
46-
...config,
48+
...restConfig,
4749
id: "discord",
48-
scope: "identify email",
50+
scope: overrideScope ?? "identify email",
4951
authorization_server,
5052
name: "Discord",
5153
algorithm: "oauth2",

src/providers/oauth2/facebook.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ type FacebookAuthConfig = OAuthBaseProviderConfig
4747
function FacebookAuthProvider(
4848
config: FacebookAuthConfig,
4949
): OAuth2ProviderConfig {
50+
const { overrideScope, ...restConfig } = config
51+
5052
return {
51-
...config,
53+
...restConfig,
5254
id: "facebook",
53-
scope: "email",
55+
scope: overrideScope ?? "email",
5456
authorization_server,
5557
name: "Facebook",
5658
algorithm: "oauth2",

0 commit comments

Comments
 (0)