Monday, December 4, 2023
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  48] [ 7]  / answers: 1 / hits: 6323  / 3 Years ago, fri, january 29, 2021, 12:00:00

In vue.js. I have the following auth.js, at the bottom of the js file it has "export default". In my Registration.vue file how do I access "actions"?


This is what I have tried:


Registration.vue


import {actions} from 'src/util/auth';
export default {
components: {
actions
},
data(){
},
methods: {
submitReg() {
console.log(actions)
}
}
}


error: export 'actions' was not found in 'src/util/auth'



This is the auth.js file full code here https://gist.github.com/toricls/5c38d2930a36262f0674c1ffa8d5134a:


import Amplify, { Auth } from 'aws-amplify';


const state = {
user: null,
};

const actions = {
async getCurrentUserInfo({ commit }) {
// This is returning null - why?
// const user = await Auth.currentUserInfo();
const user = await Auth.currentAuthenticatedUser();

const attributes = await Auth.userAttributes(user);
console.log(attributes);

commit(types.AUTHENTICATE, {
username: user.username,
...extractAttributes(attributes),
});
},

async signIn({ commit }, { username, password }) {
const user = await Auth.signIn(username, password);
const attributes = await Auth.userAttributes(user);

commit(types.AUTHENTICATE, {
username: user.username,
...extractAttributes(attributes),
});
},

async signOut() {
await Auth.signOut();
},

async signUp(_, { username, password, firstName, lastName }) {
const data = await Auth.signUp({
username,
password,
attributes: {
given_name: firstName,
family_name: lastName,
},
});
console.log(data);
},
};

const mutations = {
[types.AUTHENTICATE](state, payload) {
state.user = payload;
},
[types.SIGNOUT](state) {
state.user = null;
},
};

export default {
namespaced: true,
state,
actions,
mutations,
};

More From » vue.js

 Answers
2

There are two kinds of exports in es6 modules: named and default. When you see the braces { } in an import, that's the named import syntax. It's not the same as destructuring though it looks like it. You can't destructure inside an import statement. Change your code to:


import myExport from 'src/util/auth';
const { actions } = myExport;

Here are some examples of using both kinds of exports:


Default export examples


export default { a: 1, b: 2 } // Default object export

export default "Some string" // Default string export

Import these like:


import myExport from 'mymodule';  // no braces

Named export examples


export const myExport = { a: 1, b: 2 } // named object export

export const myExport = "Some string"  // named string export

Import these like (note the braces):


import { myExport } from 'mymodule'   // braces

[#1870] Sunday, January 24, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karladaijahf

Total Points: 78
Total Questions: 123
Total Answers: 89

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
karladaijahf questions
;