Skip to content

Commit 62300fb

Browse files
authored
Merge pull request #121 from devforth/main
put features from main to next
2 parents 546fef4 + a220022 commit 62300fb

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Why AdminForth:
2727
* Define express APIs and call them from your components and pages
2828
* Use various modern back-office-must-have plugins like audit log, files/image upload, TOTP 2FA, I18N, Copilot-style AI writing and image generation
2929

30+
3031
## Project initialisation
3132

3233
```
@@ -56,27 +57,35 @@ npx adminforth create-app
5657

5758
# For developers
5859

59-
```
60+
The most convenient way to add new features or fixes is using `dev-demo`. It imports the source code of the repository and plugins so you can edit them and see changes on the fly.
61+
62+
Fork repo, pull it and do next:
63+
64+
65+
```sh
6066
cd adminforth
6167
npm ci
6268
npm run build
6369

64-
6570
# this will install all official plugins and link adminforth package, if plugin installed it will git pull and npm ci
6671
npm run install-plugins
6772

6873
# same for official adapters
6974
npm run install-adapters
75+
```
7076

71-
# this is dev demo for development
77+
To run dev demo:
78+
```sh
7279
cd dev-demo
7380
cp .env.sample .env
7481
npm ci
7582
npm run migrate
7683
npm start
7784
```
7885

79-
Add some columns to a database. Open .prisma file, modify it, and run:
86+
## Adding columns to a database in dev-demo
87+
88+
Open `.prisma` file, modify it, and run:
8089

8190
```
8291
npm run namemigration -- --name desctiption_of_changes

adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ plugins: [
4848
new AdminForthAdapterGoogleOauth2({
4949
clientID: process.env.GOOGLE_OAUTH_CLIENT_ID,
5050
clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET,
51-
redirectUri: 'http://localhost:3000/oauth/callback',
5251
}),
5352
],
5453
emailField: 'email', // Required: field that stores the user's email
@@ -78,7 +77,7 @@ npx prisma migrate dev --name add-email-confirmed-to-adminuser
7877
3. Configure the plugin with `emailConfirmedField`:
7978

8079
```typescript title="./resources/adminuser.ts"
81-
new OAuth2Plugin({
80+
new OAuthPlugin({
8281
// ... adapters configuration ...
8382
emailField: 'email',
8483
emailConfirmedField: 'email_confirmed' // Enable email confirmation tracking
@@ -89,3 +88,35 @@ When using OAuth:
8988
- New users will have their email automatically confirmed (`email_confirmed = true`)
9089
- Existing users will have their email marked as confirmed upon successful OAuth login
9190
- The `email_confirmed` field must be a boolean type
91+
92+
### 4. Open Signup
93+
94+
By default, users must exist in the system before they can log in with OAuth. You can enable automatic user creation for new OAuth users with the `openSignup` option:
95+
96+
```typescript title="./resources/adminuser.ts"
97+
new OAuthPlugin({
98+
// ... adapters configuration ...
99+
openSignup: {
100+
enabled: true,
101+
defaultFieldValues: { // Set default values for new users
102+
role: 'user',
103+
},
104+
},
105+
}),
106+
```
107+
108+
### 5. UI Customization
109+
110+
You can customize the UI of the OAuth login buttons by using the `iconOnly` and `pill` options.
111+
112+
```typescript title="./resources/adminuser.ts"
113+
new OAuthPlugin({
114+
// ... adapters configuration ...
115+
iconOnly: true, // Show only provider icons without text
116+
pill: true, // Use pill-shaped buttons instead of rectangular
117+
}),
118+
```
119+
120+
121+
122+

adminforth/types/Adapters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export interface CompletionAdapter {
2727

2828
export interface OAuth2Adapter {
2929
getAuthUrl(): string;
30-
getTokenFromCode(code: string): Promise<{ email: string }>;
30+
getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>;
3131
getIcon(): string;
3232
}

dev-demo/resources/users.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import TwoFactorsAuthPlugin from "../../plugins/adminforth-two-factors-auth";
1111
import EmailResetPasswordPlugin from "../../plugins/adminforth-email-password-reset/index.js";
1212
import { v1 as uuid } from "uuid";
1313
import EmailAdapterAwsSes from "../../adapters/adminforth-email-adapter-aws-ses/index.js";
14-
import OAuthPlugin from "../../plugins/adminforth-oauth";
14+
15+
import OAuthPlugin from "../../plugins/adminforth-oauth";
1516
import AdminForthAdapterGoogleOauth2 from "../../adapters/adminforth-google-oauth-adapter";
16-
import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oauth-adapter";
17+
import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oauth-adapter";
18+
1719
export default {
1820
dataSource: "maindb",
1921
table: "users",

0 commit comments

Comments
 (0)