You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/events.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ Shield fires off several events during the lifecycle of the application that you
9
9
-[login](#login)
10
10
-[failedLogin](#failedlogin)
11
11
-[logout](#logout)
12
+
-[magicLogin](#magiclogin)
13
+
-[Event Timing](#event-timing)
12
14
13
15
## Responding to Events
14
16
@@ -66,6 +68,18 @@ When the magic link login fails, the following array will be provided:
66
68
67
69
Fired immediately after a successful logout. The only argument is the `User` entity.
68
70
71
+
#### magicLogin
72
+
73
+
Fired when a user has been successfully logged in via a magic link. This event does not have any parameters passed in. The authenticated user can be discovered through the `auth()` helper.
74
+
75
+
```php
76
+
Events::on('magicLogin', function() {
77
+
$user = auth()->user();
78
+
79
+
//
80
+
})
81
+
```
82
+
69
83
### Event Timing
70
84
71
85
To learn more about Event timing, please see the list below.
-[Responding to Magic Link Logins](#responding-to-magic-link-logins)
17
+
-[Session Notification](#session-notification)
18
+
-[Event](#event)
16
19
-[Authorization Flow](#authorization-flow)
17
20
-[Change Available Groups](#change-available-groups)
18
21
-[Set the Default Group](#set-the-default-group)
@@ -126,6 +129,37 @@ public array $actions = [
126
129
];
127
130
```
128
131
132
+
### Responding to Magic Link Logins
133
+
134
+
Magic Link logins allow a user that has forgotten their password to have an email sent with a unique, one-time login link. Once they've logged in you can decide how to respond. In some cases, you might want to redirect them to a special page where they must choose a new password. In other cases, you might simply want to display a one-time message prompting them to go to their account page and choose a new password.
135
+
136
+
#### Session Notification
137
+
138
+
You can detect if a user has finished the magic link login by checking for a session value, `magicLogin`. If they have recently completed the flow, it will exist and have a value of `true`.
139
+
140
+
```php
141
+
if (session('magicLogin')) {
142
+
return redirect()->route('set_password');
143
+
}
144
+
```
145
+
146
+
This value sticks around in the session for 5 minutes. Once you no longer need to take any actions, you might want to delete the value from the session.
147
+
148
+
```php
149
+
session()->removeTempdata('magicLogin');
150
+
```
151
+
152
+
#### Event
153
+
154
+
At the same time the above session variable is set, a `magicLogin`[event](https://codeigniter.com/user_guide/extending/events.html) is fired off that you may subscribe to. Note that no data is passed to the event as you can easily grab the current user from the `user()` helper or the `auth()->user()` method.
0 commit comments