Skip to content

Commit 6ff5ede

Browse files
committed
update
1 parent 95f763a commit 6ff5ede

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

blog/refine-dev-backend/index.md

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ image: ./cover.png
1313

1414
[Refine.dev](https://refine.dev/) is a very powerful and popular React-based framework for building web apps with less code. It focuses on providing high-level components and hooks to cover common use cases like authentication, authorization, and CRUD. One of the main reasons for its popularity is that it allows easy integration with many different kinds of backend systems via a flexible adapter design.
1515

16-
This post will focus on the most important type of integration: database CRUD. I'll show how easy it is, with the help of Prisma and ZenStack, to turn your database schema into a fully secured API that powers your refine app.
16+
This post will focus on the most important type of integration: database CRUD. I'll show how easy it is, with the help of Prisma and ZenStack, to turn your database schema into a fully secured API that powers your refine app. You'll see how we start by defining the data schema and access policies, derive an automatic CRUD API from it, and finally integrate with the Refine app via a "Data Provider."
1717

1818
<!-- truncate -->
1919

@@ -106,51 +106,9 @@ The `Account`, `Session`, and `VerificationToken` models are [required by Auth.j
106106

107107
### Building authentication
108108

109-
The focus of this post will be data access and access control. However, they are only possible with an authentication component in place. We'll use simple credential-based authentication in this app. Setting it up involves three parts:
110-
111-
1. Configuring an Auth.js provider to verify the user's credentials.
112-
113-
```ts title="src/auth.ts"
114-
const auth = NextAuth({
115-
...
116-
providers: [
117-
Credentials({
118-
credentials: {
119-
email: { type: 'email' },
120-
password: { type: 'password' },
121-
},
122-
123-
authorize: async (credentials) => {
124-
// find a user with matching email
125-
const user = await prisma.user.findUnique({
126-
where: { email: credentials.email },
127-
select: { id: true, email: true, password: true },
128-
});
129-
130-
// verify password hash matches
131-
if (user && (await compare(credentials.password, user.password))) {
132-
return { id: user.id, email: user.email };
133-
} else {
134-
return null;
135-
}
136-
},
137-
}),
138-
]
139-
});
140-
```
141-
142-
2. Installing an API route handler to process auth requests
143-
144-
```ts title="src/app/api/auth/[...nextauth]/route.ts"
145-
import { handlers } from '@/auth';
146-
export const { GET, POST } = handlers;
147-
```
148-
149-
3. Implementing a Refine "Authentication Provider"
150-
151-
Refine's auth provider allows you to integrate any custom authentication. You'll need to provide the implementation for routines like `register`, `login`, `logout`, etc. The completed code can be found [here](https://github.com/ymc9/refine-nextjs-zenstack/tree/main/src/providers/auth-provider).
152-
153-
We now have a working auth system that allows users to sign up and sign in.
109+
The focus of this post will be data access and access control. However, they are only possible with an authentication system in place. We'll use simple credential-based authentication in this app. The implementation involves creating an Auth.js configuration, installing an API route to handle auth requests, and implementing a Refine "Authentication Provider".
110+
111+
I won't elaborate on the details of this part, but you can find the completed code [here](https://github.com/ymc9/refine-nextjs-zenstack/tree/main/src/providers/auth-provider). It should get the registration, login, and session management parts working.
154112

155113
### Set up access control
156114

0 commit comments

Comments
 (0)