diff --git a/README.md b/README.md index 72b090ce4..231f8acb9 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Why AdminForth: * Define express APIs and call them from your components and pages * Use various modern back-office-must-have plugins like audit log, files/image upload, TOTP 2FA, I18N, Copilot-style AI writing and image generation + ## Project initialisation ``` @@ -56,19 +57,25 @@ npx adminforth create-app # For developers -``` +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. + +Fork repo, pull it and do next: + + +```sh cd adminforth npm ci npm run build - # this will install all official plugins and link adminforth package, if plugin installed it will git pull and npm ci npm run install-plugins # same for official adapters npm run install-adapters +``` -# this is dev demo for development +To run dev demo: +```sh cd dev-demo cp .env.sample .env npm ci @@ -76,7 +83,9 @@ npm run migrate npm start ``` -Add some columns to a database. Open .prisma file, modify it, and run: +## Adding columns to a database in dev-demo + +Open `.prisma` file, modify it, and run: ``` npm run namemigration -- --name desctiption_of_changes diff --git a/adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md b/adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md index 98ebae223..7d55647c9 100644 --- a/adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md +++ b/adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md @@ -48,7 +48,6 @@ plugins: [ new AdminForthAdapterGoogleOauth2({ clientID: process.env.GOOGLE_OAUTH_CLIENT_ID, clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET, - redirectUri: 'http://localhost:3000/oauth/callback', }), ], emailField: 'email', // Required: field that stores the user's email @@ -78,7 +77,7 @@ npx prisma migrate dev --name add-email-confirmed-to-adminuser 3. Configure the plugin with `emailConfirmedField`: ```typescript title="./resources/adminuser.ts" -new OAuth2Plugin({ +new OAuthPlugin({ // ... adapters configuration ... emailField: 'email', emailConfirmedField: 'email_confirmed' // Enable email confirmation tracking @@ -89,3 +88,35 @@ When using OAuth: - New users will have their email automatically confirmed (`email_confirmed = true`) - Existing users will have their email marked as confirmed upon successful OAuth login - The `email_confirmed` field must be a boolean type + +### 4. Open Signup + +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: + +```typescript title="./resources/adminuser.ts" +new OAuthPlugin({ + // ... adapters configuration ... + openSignup: { + enabled: true, + defaultFieldValues: { // Set default values for new users + role: 'user', + }, + }, +}), +``` + +### 5. UI Customization + +You can customize the UI of the OAuth login buttons by using the `iconOnly` and `pill` options. + +```typescript title="./resources/adminuser.ts" +new OAuthPlugin({ + // ... adapters configuration ... + iconOnly: true, // Show only provider icons without text + pill: true, // Use pill-shaped buttons instead of rectangular +}), +``` + + + + diff --git a/adminforth/types/Adapters.ts b/adminforth/types/Adapters.ts index 8fff98f6b..bbdc671aa 100644 --- a/adminforth/types/Adapters.ts +++ b/adminforth/types/Adapters.ts @@ -27,6 +27,6 @@ export interface CompletionAdapter { export interface OAuth2Adapter { getAuthUrl(): string; - getTokenFromCode(code: string): Promise<{ email: string }>; + getTokenFromCode(code: string, redirect_uri: string): Promise<{ email: string }>; getIcon(): string; } diff --git a/dev-demo/resources/users.ts b/dev-demo/resources/users.ts index 23770aa58..64cd1035d 100644 --- a/dev-demo/resources/users.ts +++ b/dev-demo/resources/users.ts @@ -11,9 +11,11 @@ import TwoFactorsAuthPlugin from "../../plugins/adminforth-two-factors-auth"; import EmailResetPasswordPlugin from "../../plugins/adminforth-email-password-reset/index.js"; import { v1 as uuid } from "uuid"; import EmailAdapterAwsSes from "../../adapters/adminforth-email-adapter-aws-ses/index.js"; -import OAuthPlugin from "../../plugins/adminforth-oauth"; + +import OAuthPlugin from "../../plugins/adminforth-oauth"; import AdminForthAdapterGoogleOauth2 from "../../adapters/adminforth-google-oauth-adapter"; -import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oauth-adapter"; +import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oauth-adapter"; + export default { dataSource: "maindb", table: "users",