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.

Update `AuthenticationHelpers` with new routes (#12245)

Damian Kaczmarczyk348c73994ba7
diff --git a/core/lib/generators/spree/custom_authentication/templates/authentication_helpers.rb.tt b/core/lib/generators/spree/custom_authentication/templates/authentication_helpers.rb.tt
index acfaee5a26..a67e85ebfd 100644
--- a/core/lib/generators/spree/custom_authentication/templates/authentication_helpers.rb.tt
+++ b/core/lib/generators/spree/custom_authentication/templates/authentication_helpers.rb.tt
@@ -1,21 +1,48 @@
module Spree
module AuthenticationHelpers
def self.included(receiver)
- receiver.send :helper_method, :spree_login_path
- receiver.send :helper_method, :spree_signup_path
- receiver.send :helper_method, :spree_logout_path
+ receiver.helper_method(
+ :spree_current_user,
+ :spree_login_path,
+ :spree_signup_path,
+ :spree_logout_path,
+ :spree_forgot_password_path,
+ :spree_edit_password_path,
+ :spree_admin_login_path,
+ :spree_admin_logout_path,
+ )
end
- def spree_login_path
- main_app.login_path
+ def spree_current_user
+ current_user
end
- def spree_signup_path
- main_app.signup_path
+ def spree_login_path(opts = {})
+ main_app.login_path(opts)
end
- def spree_logout_path
- main_app.logout_path
+ def spree_signup_path(opts = {})
+ main_app.signup_path(opts)
+ end
+
+ def spree_logout_path(opts = {})
+ main_app.logout_path(opts)
+ end
+
+ def spree_forgot_password_path(opts = {})
+ main_app.forgot_password_path(opts)
+ end
+
+ def spree_edit_password_path(opts = {})
+ main_app.edit_password_path(opts)
+ end
+
+ def spree_admin_login_path(opts = {})
+ main_app.admin_login_path(opts)
+ end
+
+ def spree_admin_logout_path(opts = {})
+ main_app.admin_logout_path(opts)
end
end
end
diff --git a/docs/developer/customization/authentication.mdx b/docs/developer/customization/authentication.mdx
index e9e715f7b3..daea1bb217 100644
--- a/docs/developer/customization/authentication.mdx
+++ b/docs/developer/customization/authentication.mdx
@@ -92,26 +92,48 @@ To use your own authentication system with Spree, please follow these steps:
module Spree
module AuthenticationHelpers
def self.included(receiver)
- receiver.send :helper_method, :spree_login_path
- receiver.send :helper_method, :spree_signup_path
- receiver.send :helper_method, :spree_logout_path
- receiver.send :helper_method, :spree_current_user
+ receiver.helper_method(
+ :spree_current_user,
+ :spree_login_path,
+ :spree_signup_path,
+ :spree_logout_path,
+ :spree_forgot_password_path,
+ :spree_edit_password_path,
+ :spree_admin_login_path,
+ :spree_admin_logout_path,
+ )
end
def spree_current_user
current_user
end
- def spree_login_path
- main_app.login_path
+ def spree_login_path(opts = {})
+ main_app.login_path(opts)
end
- def spree_signup_path
- main_app.signup_path
+ def spree_signup_path(opts = {})
+ main_app.signup_path(opts)
end
- def spree_logout_path
- main_app.logout_path
+ def spree_logout_path(opts = {})
+ main_app.logout_path(opts)
+ end
+
+ def spree_forgot_password_path(opts = {})
+ main_app.forgot_password_path(opts)
+ end
+
+ def spree_edit_password_path(opts = {})
+ main_app.edit_password_path(opts)
+ end
+
+ def spree_admin_login_path(opts = {})
+ main_app.admin_login_path(opts)
+ end
+
+ def spree_admin_logout_path(opts = {})
+ main_app.admin_logout_path(opts)
end
end
end
@@ -123,8 +145,12 @@ To use your own authentication system with Spree, please follow these steps:
* `spree_login_path` The location of the login/sign in form in your application.
* `spree_signup_path` The location of the sign up form in your application.
* `spree_logout_path` The location of the logout feature of your application.
+ * `spree_forgot_password_path` The location to reset a user's password.
+ * `spree_edit_password_path` The location to edit a user's password.
+ * `spree_admin_login_path` The location of the login/sign in form for the admin panel.
+ * `spree_admin_logout_path` The location of the logout feature for the admin panel.
- URLs inside the `spree_login_path`, `spree_signup_path` and `spree_logout_path` methods **must** have `main_app` prefixed if they are inside your application. This is because Spree will otherwise attempt to route to a `login_path`, `signup_path` or `logout_path` inside of itself, which does not exist. By prefixing with `main_app`, you tell it to look at the application's routes.
+ URLs inside the helpers **must** have `main_app` prefixed if they are inside your application. This is because Spree will otherwise attempt to route these paths to the Spree engine, which does not exist. By prefixing with `main_app`, you tell it to look at the application's routes.
You will need to define the `login_path`, `signup_path` and `logout_path` routes yourself, by using code like this inside your application's `config/routes.rb` if you're using Devise:
@@ -134,12 +160,14 @@ To use your own authentication system with Spree, please follow these steps:
get '/login', to: "devise/sessions#new"
get '/signup', to: "devise/registrations#new"
delete '/logout', to: "devise/sessions#destroy"
+ get '/forgot_password', to: "devise/passwords#new"
+ get '/edit_password', to: "devise/registrations#edit"
end
```
Of course, this code will be different if you're not using Devise. Simply **do not** use the `devise_scope` method and change the controllers and actions for these routes.
- You can also customize the `spree_login_path`, `spree_signup_path` and `spree_logout_path` methods inside `lib/spree/authentication_helpers.rb` to use the routing helper methods already provided by the authentication setup you have, if you wish.
+ You can also customize these methods inside `lib/spree/authentication_helpers.rb` to use the routing helper methods already provided by the authentication setup you have, if you wish.
Any modifications made to `lib/spree/authentication_helpers.rb` while the server is running will require a restart, as with any other modification to other files in `lib`.
</Accordion>