Skip to content

Commit 8e854bb

Browse files
committed
Implement autoLogin
1 parent 0db763f commit 8e854bb

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/services/Focus.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { facade } from '@noeldemartin/utils';
21
import { Events } from '@aerogel/core';
2+
import { facade, getLocationQueryParameter, hasLocationQueryParameter, objectWithout } from '@noeldemartin/utils';
3+
import { Router } from '@aerogel/plugin-routing';
4+
import { Solid } from '@aerogel/plugin-solid';
35
import type { SolidStore, SolidUserProfile } from '@noeldemartin/solid-utils';
46

57
import Service from './Focus.state';
@@ -20,6 +22,8 @@ export class FocusService extends Service {
2022
this.visits++;
2123

2224
Events.on('solid:user-profile-loaded', ([profile, store]) => this.completeProfile(profile, store));
25+
26+
this.autoLogin();
2327
}
2428

2529
protected completeProfile(profile: SolidUserProfile, store: SolidStore): void {
@@ -32,6 +36,24 @@ export class FocusService extends Service {
3236
});
3337
}
3438

39+
private async autoLogin(): Promise<void> {
40+
await Solid.booted;
41+
42+
if (
43+
Solid.isLoggedIn() ||
44+
Solid.wasLoggedIn() ||
45+
!hasLocationQueryParameter('loginWith') ||
46+
!Router.currentRoute.value
47+
) {
48+
return;
49+
}
50+
51+
const loginUrl = getLocationQueryParameter('loginWith') as string;
52+
53+
await Router.replace({ query: objectWithout(Router.currentRoute.value.query, ['loginWith']) });
54+
await Solid.login(loginUrl);
55+
}
56+
3557
}
3658

3759
export default facade(FocusService);

0 commit comments

Comments
 (0)