๐Ÿ“ฆ rust-lang / crates.io

๐Ÿ“„ -authenticated-route.js ยท 23 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class AuthenticatedRoute extends Route {
  @service router;
  @service session;

  async beforeModel(transition) {
    // wait for the `loadUserTask.perform()` of either the `application` route,
    // or the `session.login()` call
    let result = await this.session.loadUserTask.last;

    if (!result.currentUser) {
      this.session.savedTransition = transition;
      this.router.replaceWith('catch-all', {
        transition,
        loginNeeded: true,
        title: 'This page requires authentication',
      });
    }
  }
}