feat: ability to login with email, username or both (#7086)

`auth.loginWithUsername`:

```ts
auth: {
  loginWithUsername: {
    allowEmailLogin: true, // default: false
    requireEmail: false, // default: false
  }
}
```

#### `allowEmailLogin`
This property will allow you to determine if users should be able to
login with either email or username. If set to `false`, the default
value, then users will only be able to login with usernames when using
the `loginWithUsername` property.

#### `requireEmail`
Require that users also provide emails when using usernames.
This commit is contained in:
Jarrod Flesch
2024-07-18 10:29:44 -04:00
committed by GitHub
parent a3af3605f0
commit 7b3b02198c
67 changed files with 1675 additions and 1125 deletions

View File

@@ -207,6 +207,6 @@ export interface Auth {
declare module 'payload' {
// @ts-ignore
// @ts-ignore
export interface GeneratedTypes extends Config {}
}
}

View File

@@ -98,21 +98,21 @@ export class NextRESTClient {
const url = `${this.serverURL}${this.config.routes.api}/${slugs}`
return {
url,
slug: slugs.split('/'),
params: params ? qs.parse(params) : undefined,
url,
}
}
async DELETE(path: ValidPath, options: RequestInit & RequestOptions = {}): Promise<Response> {
const { url, slug, params } = this.generateRequestParts(path)
const { slug, params, url } = this.generateRequestParts(path)
const { query, ...rest } = options || {}
const queryParams = generateQueryString(query, params)
const request = new Request(`${url}${queryParams}`, {
...rest,
method: 'DELETE',
headers: this.buildHeaders(options),
method: 'DELETE',
})
return this._DELETE(request, { params: { slug } })
}
@@ -121,14 +121,14 @@ export class NextRESTClient {
path: ValidPath,
options: Omit<RequestInit, 'body'> & RequestOptions = {},
): Promise<Response> {
const { url, slug, params } = this.generateRequestParts(path)
const { slug, params, url } = this.generateRequestParts(path)
const { query, ...rest } = options || {}
const queryParams = generateQueryString(query, params)
const request = new Request(`${url}${queryParams}`, {
...rest,
method: 'GET',
headers: this.buildHeaders(options),
method: 'GET',
})
return this._GET(request, { params: { slug } })
}
@@ -140,8 +140,8 @@ export class NextRESTClient {
`${this.serverURL}${this.config.routes.api}${this.config.routes.graphQL}${queryParams}`,
{
...rest,
method: 'POST',
headers: this.buildHeaders(options),
method: 'POST',
},
)
return this._GRAPHQL_POST(request)
@@ -154,8 +154,8 @@ export class NextRESTClient {
const request = new Request(`${url}${queryParams}`, {
...rest,
method: 'PATCH',
headers: this.buildHeaders(options),
method: 'PATCH',
})
return this._PATCH(request, { params: { slug } })
}
@@ -164,12 +164,12 @@ export class NextRESTClient {
path: ValidPath,
options: FileArg & RequestInit & RequestOptions = {},
): Promise<Response> {
const { url, slug, params } = this.generateRequestParts(path)
const { slug, params, url } = this.generateRequestParts(path)
const queryParams = generateQueryString({}, params)
const request = new Request(`${url}${queryParams}`, {
...options,
method: 'POST',
headers: this.buildHeaders(options),
method: 'POST',
})
return this._POST(request, { params: { slug } })
}