File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -124,3 +124,16 @@ export default function({ app }) {
124
124
})
125
125
}
126
126
```
127
+
128
+ ### ` onRedirect(handler) `
129
+
130
+ Pre-process URLs before redirect: (` plugins/auth.js ` )
131
+
132
+ ``` js
133
+ export default function ({ app }) {
134
+ app .$auth .onRedirect ((to , from ) => {
135
+ console .error (to)
136
+ // you can optionally change `to` by returning a new value
137
+ })
138
+ }
139
+ ```
Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ export default class Auth {
14
14
// Error listeners
15
15
this . _errorListeners = [ ]
16
16
17
+ // Redirect listeners
18
+ this . _redirectListeners = [ ]
19
+
17
20
// Storage & State
18
21
options . initialState = { user : null , loggedIn : false }
19
22
const storage = new Storage ( ctx , options )
@@ -352,6 +355,9 @@ export default class Auth {
352
355
}
353
356
}
354
357
358
+ // Call onRedirect hook
359
+ to = this . callOnRedirect ( to , from ) || to
360
+
355
361
// Prevent infinity redirects
356
362
if ( isSameURL ( to , from ) ) {
357
363
return
@@ -368,6 +374,17 @@ export default class Auth {
368
374
}
369
375
}
370
376
377
+ onRedirect ( listener ) {
378
+ this . _redirectListeners . push ( listener )
379
+ }
380
+
381
+ callOnRedirect ( to , from ) {
382
+ for ( const fn of this . _redirectListeners ) {
383
+ to = fn ( to , from ) || to
384
+ }
385
+ return to
386
+ }
387
+
371
388
hasScope ( scope ) {
372
389
const userScopes = this . $state . user && getProp ( this . $state . user , this . options . scopeKey )
373
390
You can’t perform that action at this time.
0 commit comments