Skip to content

Commit

Permalink
Implement LSSAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Aug 16, 2024
1 parent adb0d2a commit 33179ba
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 204 deletions.
416 changes: 225 additions & 191 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"test:serve-pod": "community-solid-server -l warn"
},
"dependencies": {
"@aerogel/core": "next",
"@aerogel/plugin-i18n": "next",
"@aerogel/plugin-solid": "next",
"@aerogel/plugin-soukai": "next",
"@aerogel/core": "0.0.0-next.b243de4e2590f02709edeebd8c13b74087592c04",
"@aerogel/plugin-i18n": "0.0.0-next.13b88f634a31caf3669d61e53e7d3fa95e20488c",
"@aerogel/plugin-solid": "0.0.1-next.bba0a15680b1b426603cd45efbfabced5852d433",
"@aerogel/plugin-soukai": "0.0.0-next.d91fa1b09d159896747a54add57983993ddb97c4",
"@intlify/unplugin-vue-i18n": "^0.12.2",
"@noeldemartin/utils": "next",
"@noeldemartin/utils": "0.5.1-next.82707467527729a9fe7c2155959beb4b5ea30b81",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"soukai": "next",
"soukai-solid": "0.5.2-next.b6340345e228903e404a02c1ed9be8fc95162e8f",
"soukai": "0.5.2-next.376c89f9aaf5d42e43c169445d10fd87ec6aab2d",
"soukai-solid": "0.5.2-next.6fb8ad070edeb38e0d9dd14c5024af694a5fe340",
"tailwindcss": "^3.3.2",
"vue": "^3.3.0",
"vue-i18n": "9.3.0-beta.19"
Expand Down
44 changes: 44 additions & 0 deletions src/auth/LSSAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Storage, after, fail } from '@noeldemartin/utils';
import { Authenticator, Solid } from '@aerogel/plugin-solid';
import type { AuthSession } from '@aerogel/plugin-solid';

const STORAGE_KEY = 'lss';

interface StorageData {
loginUrl: string;
}

export default class LSSAuthenticator extends Authenticator {

public async login(loginUrl: string): Promise<AuthSession> {
Storage.set<StorageData>(STORAGE_KEY, { loginUrl });

// TODO support authentication without reloading
location.reload();

// Browser should reload, so just make it wait for a while.
await after({ seconds: 60 });

return fail('Browser should have reloaded, but it didn\'t');
}

public async logout(): Promise<void> {
Storage.remove(STORAGE_KEY);

await this.endSession();
}

protected async restoreSession(): Promise<void> {
if (!Storage.has(STORAGE_KEY)) {
return;
}

const { loginUrl } = Storage.require<StorageData>(STORAGE_KEY);
const webId = `${loginUrl}/profile/card#me`;
const user = await Solid.requireUserProfile(webId);

await this.initAuthenticatedFetch(window.fetch.bind(window));
await this.startSession({ loginUrl, user });
}

}
11 changes: 11 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import LSSAuthenticator from '@/auth/LSSAuthenticator';

export const authenticators = {
lss: new LSSAuthenticator(),
};

export type RamenAuthenticators = typeof authenticators;

declare module '@aerogel/plugin-solid' {
interface Authenticators extends RamenAuthenticators {}
}
4 changes: 2 additions & 2 deletions src/components/AppLoginError.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import { computed } from 'vue';
import { Solid } from '@aerogel/plugin-solid';
import { Errors, translate } from '@aerogel/core';
import { getErrorMessage, translate } from '@aerogel/core';
const errorMessage = computed(() => {
if (!Solid.error) {
return;
}
const message = Errors.getErrorMessage(Solid.error);
const message = getErrorMessage(Solid.error);
return translate('login.errorInfo', { message });
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/lib/InlineSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
v-for="(option, index) in $select?.options"
v-slot="{ active, selected }: IAGHeadlessSelectOptionSlotProps"
:key="index"
:value="option.value"
:value="option"
as="template"
>
<li
Expand All @@ -30,7 +30,7 @@
'font-medium': selected,
}"
>
{{ option.text }}
{{ option }}
</li>
</AGHeadlessSelectOption>
</AGHeadlessSelectOptions>
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bootstrap } from '@aerogel/core';

import './assets/css/styles.css';
import App from './App.vue';
import { authenticators } from './auth';
import { components } from './components';
import { services } from './services';

Expand All @@ -14,6 +15,6 @@ bootstrap(App, {
plugins: [
i18n({ messages: import.meta.glob('@/lang/*.yaml') }),
soukai({ models: import.meta.glob(['@/models/*', '!**/*.test.ts'], { eager: true }) }),
solid({ autoReconnect: true }),
solid({ authenticators, defaultAuthenticator: 'lss' }),
],
});
2 changes: 1 addition & 1 deletion src/services/Cookbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ export class CookbookService extends Service {

}

export default facade(new CookbookService());
export default facade(CookbookService);

0 comments on commit 33179ba

Please sign in to comment.