Skip to content

Commit

Permalink
Merge branch 'next' of github.com:devforth/adminforth into next
Browse files Browse the repository at this point in the history
  • Loading branch information
ivictbor committed Feb 22, 2025
2 parents 98cd416 + 62300fb commit 9c5d0c1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down Expand Up @@ -56,27 +57,35 @@ 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
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
Expand Down
35 changes: 33 additions & 2 deletions adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ plugins: [
new AdminForthAdapterGoogleOauth2({
clientID: process.env.GOOGLE_OAUTH_CLIENT_ID,
clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/oauth/callback',
}),
],

Expand Down Expand Up @@ -88,7 +87,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
Expand All @@ -99,3 +98,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
}),
```




2 changes: 1 addition & 1 deletion adminforth/types/Adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 4 additions & 2 deletions dev-demo/resources/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9c5d0c1

Please sign in to comment.