Skip to content

Commit 2258ebc

Browse files
Merge pull request #17 from graphql-devise/new-dir-for-email-templates
Use new dir for email templates
2 parents 1c7b8ea + 0b12907 commit 2258ebc

7 files changed

Lines changed: 24 additions & 6 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ class User < ApplicationRecord
8484
end
8585
```
8686

87+
### Customizing Email Templates
88+
The approach of this gem is a bit different from DeviseTokenAuth. We have placed our templates in `app/views/graphql_devise/mailer`,
89+
so if you want to change them, place yours on the same dir structure on your Rails project. You can customize these two templates:
90+
1. `app/views/graphql_devise/mailer/confirmation_instructions.html.erb`
91+
1. `app/views/graphql_devise/mailer/reset_password_instructions.html.erb`
92+
93+
The main reason for this difference is just to make it easier to have both Standard `Devise` and this gem running at the same time.
94+
Check [these files](app/views/graphql_devise/mailer) to see the available helper methods you can use in the views.
95+
8796
### Authenticating Controller Actions
8897
Just like with Devise or DTA, you will need to authenticate users in your controllers.
8998
For this you need to call `authenticate_<model>!` in a before_action hook of your controller.
@@ -125,6 +134,13 @@ you can use [our specs](https://github.com/graphql-devise/graphql_devise/tree/b5
125134
Also, the [dummy app](https://github.com/graphql-devise/graphql_devise/tree/b5985036e01ea064e43e457b4f0c8516f172471c/spec/dummy) used in our specs will give you
126135
a clear idea on how to configure the gem on your Rails application.
127136

137+
### Using Alongside Standard Devise
138+
The DeviseTokenAuth gem allows experimental use of the standard Devise gem to be configured at the same time, for more
139+
information you can check [this answer here](https://github.com/lynndylanhurley/devise_token_auth/blob/2a32f18ccce15638a74e72f6cfde5cf15a808d3f/docs/faq.md#can-i-use-this-gem-alongside-standard-devise).
140+
141+
This gem supports the same and should be easier to handle email templates due to the fact we don't override standard Devise
142+
templates.
143+
128144
## Future Work
129145
We will continue to improve the gem and add better docs.
130146

app/graphql/graphql_devise/mutations/send_password_reset.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ def resolve(email:, redirect_url:)
1010
if resource
1111
yield resource if block_given?
1212
resource.send_reset_password_instructions(
13-
email: email,
14-
provider: 'email',
15-
redirect_url: redirect_url
13+
email: email,
14+
provider: 'email',
15+
redirect_url: redirect_url,
16+
template_path: ['graphql_devise/mailer']
1617
)
1718

1819
if resource.errors.empty?

app/graphql/graphql_devise/mutations/sign_up.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def resolve(confirm_success_url: nil, config_name: nil, **attrs)
1919
if requires_confirmation?(resource)
2020
resource.send_confirmation_instructions(
2121
client_config: config_name,
22-
redirect_url: confirm_success_url
22+
redirect_url: confirm_success_url,
23+
template_path: ['graphql_devise/mailer']
2324
)
2425
end
2526

app/views/devise/mailer/confirmation_instructions.html.erb renamed to app/views/graphql_devise/mailer/confirmation_instructions.html.erb

File renamed without changes.

app/views/devise/mailer/reset_password_instructions.html.erb renamed to app/views/graphql_devise/mailer/reset_password_instructions.html.erb

File renamed without changes.

spec/requests/mutations/send_password_reset_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
expect do
3333
get link['href']
3434
user.reload
35-
end.to change { user.allow_password_change }.from(false).to(true)
35+
end.to change(user, :allow_password_change).from(false).to(true)
3636
end
3737
end
3838

spec/requests/queries/confirm_account_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
context 'when confirmation token is correct' do
2323
let(:token) { user.confirmation_token }
2424

25-
before { user.send_confirmation_instructions }
25+
before { user.send_confirmation_instructions(template_path: ['graphql_devise/mailer']) }
2626

2727
it 'confirms the resource and redirects to the sent url' do
2828
expect do

0 commit comments

Comments
 (0)