Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Make the Rails app template a headless, gem-owned install

Łukasz Adamczykc8c818e64d15
diff --git a/packages/dashboard/src/routes/login.tsx b/packages/dashboard/src/routes/login.tsx
index fa1463402f..4da3beed87 100644
--- a/packages/dashboard/src/routes/login.tsx
+++ b/packages/dashboard/src/routes/login.tsx
@@ -1,4 +1,5 @@
import { zodResolver } from '@hookform/resolvers/zod'
+import { SpreeError } from '@spree/admin-sdk'
import { useAuth } from '@spree/dashboard-core'
import { Button, Input, Label } from '@spree/dashboard-ui'
import { createFileRoute, Link, Navigate } from '@tanstack/react-router'
@@ -24,8 +25,13 @@ function LoginPage() {
const onSubmit = async (data: LoginFormValues) => {
try {
await login(data.email, data.password)
- } catch {
- form.setError('root', { message: t('admin.validation.invalid_email_or_password') })
+ } catch (err) {
+ // Surface the server's message (e.g. account lockout) — bad credentials and
+ // lockout share a code, so the message is the only distinguishing signal.
+ // Fall back to the generic string for network/unexpected errors.
+ const message =
+ err instanceof SpreeError ? err.message : t('admin.validation.invalid_email_or_password')
+ form.setError('root', { message })
}
}
diff --git a/spree/core/db/migrate/20250122113708_add_first_and_last_name_to_spree_admin_class.rb b/spree/core/db/migrate/20250122113708_add_first_and_last_name_to_spree_admin_class.rb
deleted file mode 100644
index aaebc1d131..0000000000
--- a/spree/core/db/migrate/20250122113708_add_first_and_last_name_to_spree_admin_class.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class AddFirstAndLastNameToSpreeAdminClass < ActiveRecord::Migration[6.1]
- def change
- if Spree.admin_user_class.present?
- admin_users_table_name = Spree.admin_user_class.table_name
- add_column admin_users_table_name, :first_name, :string unless column_exists?(admin_users_table_name, :first_name)
- add_column admin_users_table_name, :last_name, :string unless column_exists?(admin_users_table_name, :last_name)
- end
- end
-end
diff --git a/spree/core/db/migrate/20250508060800_add_selected_locale_to_spree_admin_users.rb b/spree/core/db/migrate/20250508060800_add_selected_locale_to_spree_admin_users.rb
deleted file mode 100644
index b130dd9e63..0000000000
--- a/spree/core/db/migrate/20250508060800_add_selected_locale_to_spree_admin_users.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class AddSelectedLocaleToSpreeAdminUsers < ActiveRecord::Migration[7.2]
- def change
- if Spree.admin_user_class.present?
- users_table_name = Spree.admin_user_class.table_name
- add_column users_table_name, :selected_locale, :string unless column_exists?(users_table_name, :selected_locale)
- end
- end
-end
diff --git a/spree/template.rb b/spree/template.rb
index e970dcba87..971ce1cdbe 100644
--- a/spree/template.rb
+++ b/spree/template.rb
@@ -1,8 +1,15 @@
# Spree Commerce Rails Application Template
-# This template sets up a new Rails application with Spree Commerce
+# Sets up a new headless Rails application (Spree core + API) using the gem-owned
+# Spree::Customer / Spree::AdminUser auth models (has_secure_password). The admin
+# UI is the React dashboard (@spree/dashboard) talking to the Admin API.
LOAD_SAMPLE_DATA = ENV['LOAD_SAMPLE_DATA'] == 'true'
USE_LOCAL_SPREE = ENV['USE_LOCAL_SPREE'] == 'true'
+# Monorepo root (the dir that contains the `spree` gem dir) for USE_LOCAL_SPREE
+# (dev only). A path source rooted at `<root>/spree` exposes every nested
+# gemspec (spree, spree_core, spree_api, spree_emails, …) via Bundler's default
+# glob, resolving the whole stack locally.
+SPREE_LOCAL_PATH = ENV['SPREE_LOCAL_PATH'] || '.'
ADMIN_EMAIL = ENV['ADMIN_EMAIL'] || '[email protected]'
ADMIN_PASSWORD = ENV['ADMIN_PASSWORD'] || 'spree123'
SPREE_VERSION = ENV['SPREE_VERSION'] || '>= 5.4.2'
@@ -10,15 +17,11 @@ SPREE_VERSION = ENV['SPREE_VERSION'] || '>= 5.4.2'
def add_gems
say 'Adding required gems to Gemfile...', :blue
- # Core dependencies
- gem 'devise'
-
# Spree gems - core (includes core, api, cli)
- gem 'spree', USE_LOCAL_SPREE ? { path: '.' } : { version: SPREE_VERSION }
+ gem 'spree', USE_LOCAL_SPREE ? { path: File.join(SPREE_LOCAL_PATH, 'spree') } : { version: SPREE_VERSION }
# Optional Spree packages
- gem 'spree_emails', USE_LOCAL_SPREE ? { path: '../emails' } : { version: SPREE_VERSION }
- gem 'spree_admin', USE_LOCAL_SPREE ? { path: '../admin' } : { version: SPREE_VERSION }
+ gem 'spree_emails', USE_LOCAL_SPREE ? { path: File.join(SPREE_LOCAL_PATH, 'spree', 'emails') } : { version: SPREE_VERSION }
# translations
gem 'spree_i18n'
@@ -31,28 +34,13 @@ def add_gems
end
end
-def setup_auth
- say 'Setting up authentication...', :blue
-
- generate 'devise:install'
- generate 'devise', 'Spree::User'
- generate 'devise', 'Spree::AdminUser'
-end
-
def install_spree
say 'Running Spree installer (core, api, cli)...', :blue
- # Run Spree installer with migrations but without seeds - seeds run after all generators complete
- generate 'spree:install', '--force', '--auto-accept', '--seed=false',
- '--user_class=Spree::User', '--admin_user_class=Spree::AdminUser',
- '--authentication=devise'
-end
-
-def install_spree_admin
- say 'Installing Spree Admin...', :blue
-
- generate 'spree:admin:install', '--force'
- generate 'spree:admin:devise', '--force'
+ # Run Spree installer with migrations but without seeds - seeds run after all
+ # generators complete. Uses the gem-owned Spree::Customer / Spree::AdminUser
+ # defaults (has_secure_password); no --authentication scaffolding.
+ generate 'spree:install', '--force', '--auto-accept', '--seed=false'
end
def configure_development_environment
@@ -71,15 +59,6 @@ def configure_development_environment
end
end
-def setup_procfile
- say 'Setting up Procfile.dev...', :blue
-
- # Add web server to Procfile.dev
- append_to_file 'Procfile.dev' do
- "\nweb: bin/rails s -p 3000\n"
- end
-end
-
def seed_database
say 'Loading seed data...', :blue
@@ -104,9 +83,9 @@ def show_success_message
say
say 'Then visit:', :yellow
say ' Store API: http://localhost:3000/api/v3/store', :bold
- say ' Admin Panel: http://localhost:3000/admin', :bold
+ say ' Admin API: http://localhost:3000/api/v3/admin', :bold
say
- say 'Admin credentials:', :yellow
+ say 'Admin account (sign in via the Admin API / React dashboard):', :yellow
say " Email: #{ADMIN_EMAIL}", :bold
say " Password: #{ADMIN_PASSWORD}", :bold
say
@@ -121,10 +100,7 @@ add_gems
after_bundle do
configure_development_environment
- setup_auth
install_spree
- install_spree_admin
- setup_procfile
seed_database
load_sample_data
show_success_message