Skip to content

Commit

Permalink
Merge branch 'main' into email-docs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Whats-A-MattR authored Nov 12, 2024
2 parents f60c044 + 4b01b46 commit 6f12e9a
Show file tree
Hide file tree
Showing 44 changed files with 243 additions and 170 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,22 @@ We have an [OpenCollective](https://opencollective.com/nextauth) for companies a
<div>Encore</div>
<sub>💵</sub>
</td>
<td align="center" valign="top">
<a href="https://sent.dm/?ref=auth.js" target="_blank">
<img width="108" src="https://avatars.githubusercontent.com/u/153308555?v=4" alt="Sent.dm Logo" />
</a><br />
<div>Sent.dm</div>
<sub>💵</sub>
</td>
</tr>
<tr>
<td align="center" valign="top">
<a href="https://arcjet.com/?ref=auth.js" target="_blank">
<img width="108" src="https://avatars.githubusercontent.com/u/24397786?s=200&v=4" alt="Arcjet Logo" />
</a><br />
<div>Arcjet</div>
<sub>💵</sub>
</td>
</tr>
<tr>
<td align="center" valign="top">
<a href="https://route4me.com/?ref=auth.js" target="_blank">
<img width="108" src="https://avatars.githubusercontent.com/u/7936820?v=4" alt="Route4Me Logo" />
Expand Down
67 changes: 35 additions & 32 deletions docs/pages/getting-started/authentication/credentials.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@ import { Code } from "@/components/Code"

# Credentials

To setup Auth.js with external authentication mechanisms or simply use username and password, we need to use the `Credentials` provider. This provider is designed to forward any credentials inserted into the login form (i.e. username/password) to your authentication service via the `authorize` callback on the provider configuration.
To setup Auth.js with any external authentication mechanisms or use a traditional username/email and password flow, we can use the `Credentials` provider. This provider is designed to forward any credentials inserted into the login form (i.e. username/password, but not limited to) to your authentication service.

<Callout type="warning">
The industry has come a long way since usernames and passwords
as the go-to mechanism for authenticating and authorizing users to
web applications. Therefore, if possible, we recommend a more modern and
secure authentication mechanism such as any of the [OAuth
providers](/getting-started/authentication/oauth), [Email Magic
Links](/getting-started/authentication/email), or [WebAuthn
(Passkeys)](/getting-started/authentication/webauthn) options instead.

However, we also want to be flexible and support anything
you deem appropriate for your application and use case,
so there are no plans to remove this provider.

</Callout>

<Callout>
By default, the Credentials provider does not persist data in the database.
However, you can still create and save any data in your database, you just
have to provide the necessary logic, eg. to encrypt passwords, add
rate-limiting, add password reset functionality, etc.
</Callout>

<Steps>

Expand Down Expand Up @@ -44,8 +66,8 @@ export const { handlers, signIn, signOut, auth } = NextAuth({

if (!user) {
// No user found, so this is their first attempt to login
// meaning this is also the place you could do registration
throw new Error("User not found.")
// Optionally, this is also the place you could do a user registration
throw new Error("Invalid credentials.")
}

// return user object with their profile data
Expand Down Expand Up @@ -110,7 +132,9 @@ export const { signIn, signOut, handle } = SvelteKitAuth({
user = await getUserFromDb(credentials.email, pwHash)

if (!user) {
throw new Error("User not found.")
// No user found, so this is their first attempt to login
// Optionally, this is also the place you could do a user registration
throw new Error("Invalid credentials.")
}

// return JSON object with the user data
Expand Down Expand Up @@ -161,8 +185,8 @@ app.use(

if (!user) {
// No user found, so this is their first attempt to login
// meaning this is also the place you could do registration
throw new Error("User not found.")
// Optionally, this is also the place you could do a user registration
throw new Error("Invalid credentials.")
}

// return user object with the their profile data
Expand Down Expand Up @@ -305,15 +329,15 @@ export default component$(() => {

</Steps>

## Verifying Data with Zod
## Validating credentials

To improve the security of your `Credentials` provider use, we can leverage a run-time schema validation library like [Zod](https://zod.dev) to validate that the inputs match what we expect.
Always validate the credentials server-side, i.e. by leveraging a schema validation library like [Zod](https://zod.dev).

```bash npm2yarn
npm install zod
```

Next, we'll setup the schema and parsing in our `auth.ts` configuration file, using the `authorize` callback on the `Credentials` provider.
Next, we'll set up the schema and parsing in our `auth.ts` configuration file, using the `authorize` callback on the `Credentials` provider.

<Code>
<Code.Next>
Expand Down Expand Up @@ -363,7 +387,7 @@ export const { handlers, auth } = NextAuth({
user = await getUserFromDb(email, pwHash)

if (!user) {
throw new Error("User not found.")
throw new Error("Invalid credentials.")
}

// return JSON object with the user data
Expand Down Expand Up @@ -470,7 +494,7 @@ export const { handle } = SvelteKitAuth({
user = await getUserFromDb(email, pwHash)

if (!user) {
throw new Error("User not found.")
throw new Error("Invalid credentials.")
}

// return JSON object with the user data
Expand All @@ -489,24 +513,3 @@ export const { handle } = SvelteKitAuth({

</Code.Svelte>
</Code>

<Callout type="warning">
The industry has come a long way since usernames and passwords were first
introduced as the go-to mechanism for authenticating and authorizing users to
web applications. Therefore, if possible, we recommend a more modern and
secure authentication mechanism such as any of the [OAuth
providers](/getting-started/authentication/oauth), [Email Magic
Links](/getting-started/authentication/email), or [WebAuthn
(Passkeys)](/getting-started/authentication/webauthn) options instead of
username / password.

However, we also want to be flexible and support anything
you deem appropriate for your application and use-case.

</Callout>

<Callout>
The Credentials provider only supports the JWT session strategy. You can still
create and save a database session and reference it from the JWT via an id,
but you'll need to provide that logic yourself.
</Callout>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { auth } from "../auth"
export default async function UserAvatar() {
const session = await auth()

if (!session.user) return null
if (!session?.user) return null

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/edge-compatibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default async function Page() {

return (
<div className="container">
<pre>{session}</pre>
<pre>{JSON.stringify(session, null, 2)}</pre>
</div>
)
}
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/sponsors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ It would not be possible without the generous support of our sponsors.
"https://avatars.githubusercontent.com/u/77690634?v=4",
"Neon",
],
[
"https://sent.dm",
"https://avatars.githubusercontent.com/u/153308555?v=4",
"Sent.dm",
],
].map(([href, src, name]) => (
<a
key={name}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-azure-tables/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/azure-tables-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Azure Tables Storage adapter for next-auth.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-d1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/d1-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "A Cloudflare D1 adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-dgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/dgraph-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Dgraph adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-drizzle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/drizzle-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Drizzle adapter for Auth.js.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-dynamodb/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@auth/dynamodb-adapter",
"repository": "https://github.com/nextauthjs/next-auth",
"version": "2.7.2",
"version": "2.7.3",
"description": "AWS DynamoDB adapter for next-auth.",
"keywords": [
"next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-edgedb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/edgedb-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "EdgeDB adapter for next-auth.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-fauna/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/fauna-adapter",
"version": "3.7.2",
"version": "3.7.3",
"description": "Fauna Adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-firebase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/firebase-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Firebase adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-hasura/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/hasura-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Hasura adapter for Auth.js.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-kysely/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/kysely-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Kysely adapter for Auth.js",
"homepage": "https://authjs.dev/reference/adapter/kysely",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-mikro-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/mikro-orm-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "MikroORM adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-mongodb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/mongodb-adapter",
"version": "3.7.2",
"version": "3.7.3",
"description": "MongoDB adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-neo4j/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/neo4j-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "neo4j adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-pg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/pg-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Postgres adapter for next-auth.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-pouchdb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/pouchdb-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "PouchDB adapter for next-auth.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-prisma/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/prisma-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Prisma adapter for Auth.js",
"homepage": "https://authjs.dev/reference/adapter/prisma",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sequelize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/sequelize-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Sequelize adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-supabase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/supabase-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Supabase adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-surrealdb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/surrealdb-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "SurrealDB adapter for next-auth.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-typeorm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/typeorm-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "TypeORM adapter for Auth.js.",
"homepage": "https://authjs.dev/reference/adapter/typeorm",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-unstorage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/unstorage-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Unstorage adapter for Auth.js.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-upstash-redis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/upstash-redis-adapter",
"version": "2.7.2",
"version": "2.7.3",
"description": "Upstash adapter for Auth.js.",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-xata/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/xata-adapter",
"version": "1.7.2",
"version": "1.7.3",
"description": "Xata adapter for Auth.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth/core",
"version": "0.37.2",
"version": "0.37.3",
"description": "Authentication for the Web.",
"keywords": [
"authentication",
Expand Down
Loading

0 comments on commit 6f12e9a

Please sign in to comment.