generated from Authress/vue-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthressClient.ts
37 lines (30 loc) · 1.46 KB
/
authressClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { LoginClient } from '@authress/login';
let loginClient: LoginClient = null;
try {
loginClient = new LoginClient({
// app_default is the default Authress created application.
// * Configure the default Authress application at https://authress.io/app/#/settings?focus=applications&applicationId=app_default
// * Create a new application at https://authress.io/app/#/settings?focus=applications
// * Or Create an application using the quick setup flow: https://authress.io/app/#/settings?focus=quick&flow=authentication
applicationId: 'app_default',
// Create a custom domain: https://authress.io/app/#/settings?focus=domain (https://login.application.com)
// * OR use the default one for your account: https://authress.io/app/#/api?route=overview (https://ACCOUNT_ID.api-region.authress.io)
// https://a48copjrf5qrjn1niakfzfqlp.api-eu-west.authress.io
authressLoginHostUrl: 'https://a48copjrf5qrjn1niakfzfqlp.login.authress.io',
});
// loginClient.userSessionExists();
} catch (error) {
loginClient = null;
console.error(error);
}
export const starterKitIsConfiguredCorrectly = !!loginClient;
export const authressLoginClient = loginClient;
export async function ensureUserIsLoggedIn(next: () => void) {
const userIsLoggedIn = await loginClient.userSessionExists();
if (!userIsLoggedIn) {
console.log('User is not logged on the protected route, redirecting to unauthorized');
next('Unauthorized');
return;
}
next();
}