Last active
October 26, 2021 18:24
Revisions
-
maoosi revised this gist
Jan 26, 2021 . No changes.There are no files selected for viewing
-
maoosi revised this gist
Jan 26, 2021 . No changes.There are no files selected for viewing
-
maoosi revised this gist
Jan 26, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,10 +39,10 @@ export default class AmplifyAuthScheme { async fetchUser() { try { const user = await this._Auth().currentAuthenticatedUser() const { attributes } = process.server ? await this._Auth().currentUserInfo() : user this.$auth.setUser(attributes) return user } catch (error) { this.$auth.callOnError(error, { method: 'fetchUser' }) -
maoosi revised this gist
Jan 26, 2021 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,8 +38,10 @@ export default class AmplifyAuthScheme { async fetchUser() { try { const user = await this._Auth().currentAuthenticatedUser() const userAttributes = process.server ? await this._Auth().currentUserInfo() : user this.$auth.setUser(userAttributes) return user } catch (error) { -
maoosi revised this gist
Jan 26, 2021 . 1 changed file with 6 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,20 +21,12 @@ export default class AmplifyAuthScheme { } async mounted() { // https://docs.amplify.aws/lib/auth/getting-started/q/platform/js#configure-your-application Amplify.configure({ /* aws config here */ }) return this.$auth.fetchUserOnce() } async login({ username, password }:{ username: string, password: string }) { try { await this.$auth.reset() await this._Auth().signIn(username, password) @@ -46,20 +38,9 @@ export default class AmplifyAuthScheme { async fetchUser() { try { let userAttributes = await this._Auth().currentAuthenticatedUser() if (process.server) userAttributes = await this._Auth().currentUserInfo() this.$auth.setUser(userAttributes) return user } catch (error) { this.$auth.callOnError(error, { method: 'fetchUser' }) -
maoosi revised this gist
Jan 26, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export default class AmplifyAuthScheme { async mounted() { Amplify.configure({ /* aws config here */ /* https://docs.amplify.aws/lib/auth/getting-started/q/platform/js#configure-your-application */ }) return this.$auth.fetchUserOnce() } -
maoosi revised this gist
Jan 26, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,9 @@ export default class AmplifyAuthScheme { } async mounted() { Amplify.configure({ /* aws config here */ }) return this.$auth.fetchUserOnce() } -
maoosi renamed this gist
Jan 26, 2021 . 1 changed file with 1 addition and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,17 +21,7 @@ export default class AmplifyAuthScheme { } async mounted() { Amplify.configure(amplifyConfig) return this.$auth.fetchUserOnce() } -
maoosi revised this gist
Jan 26, 2021 . No changes.There are no files selected for viewing
-
maoosi created this gist
Jan 26, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ import { Amplify, Auth, withSSRContext } from 'aws-amplify' import { Auth as NuxtAuth } from '@nuxtjs/auth-next' export interface AmplifyAuthSchemeOptions { name: string } export default class AmplifyAuthScheme { public $auth: NuxtAuth public options: AmplifyAuthSchemeOptions constructor($auth: NuxtAuth, options: AmplifyAuthSchemeOptions) { this.$auth = $auth this.options = options } _Auth(): typeof Auth { return process.server ? withSSRContext({ req: this.$auth.ctx.req }).Auth : Auth } async mounted() { if (process.server) { const amplifyConfig = await this.$auth.ctx.store.dispatch( 'getAmplifyConfig', { runtimeConfig: this.$auth.ctx.$config, isDev: this.$auth.ctx.isDev, } ) Amplify.configure(amplifyConfig) } return this.$auth.fetchUserOnce() } async login({ username, password, }: { username: string password: string }) { try { await this.$auth.reset() await this._Auth().signIn(username, password) return this.$auth.fetchUser() } catch (error) { this.$auth.callOnError(error, { method: 'login' }) } } async fetchUser() { try { const user = await this._Auth().currentAuthenticatedUser() if (process.server) { const infos = await this._Auth().currentUserInfo() this.$auth.setUser({ email: infos.attributes.email, }) } else { this.$auth.setUser({ email: user.attributes.email, }) } return user } catch (error) { this.$auth.callOnError(error, { method: 'fetchUser' }) } } reset() { this.$auth.setUser(false) } async logout() { try { await this._Auth().signOut() return this.$auth.reset() } catch (error) { this.$auth.callOnError(error, { method: 'logout' }) } } }