This commit is contained in:
이진석
2020-01-31 18:55:28 +09:00
parent 85f1962332
commit c2eb47fd9d
2 changed files with 32 additions and 35 deletions

View File

@@ -12,7 +12,6 @@ function login(data) {
}); });
} }
function register(data) { function register(data) {
const { email, name, password } = data; const { email, name, password } = data;
return axios({ return axios({
@@ -26,7 +25,7 @@ function register(data) {
}); });
} }
function currentUser(token) { function session(token) {
return axios({ return axios({
method: 'get', method: 'get',
url: '/api/users', url: '/api/users',
@@ -38,6 +37,6 @@ function currentUser(token) {
export default { export default {
login, login,
currentUser, session,
register register
} }

View File

@@ -8,48 +8,46 @@
<button type="submit">확인</button> <button type="submit">확인</button>
</form> </form>
<button type="button" @click="currentUser">세션확인</button> <button type="button" @click="session">세션확인</button>
</div> </div>
</template> </template>
<script> <script>
import authApi from "../../api/authApi"; import authApi from "../../api/authApi";
export default { export default {
name: "Login", name: "Login",
data() { data() {
return { return {
email: '', email: '',
password: '' password: ''
} }
}, },
methods: { methods: {
submit: async function(evt) { submit: async function(evt) {
evt.preventDefault(); evt.preventDefault();
const { email, password } = this;
const { email, password } = this; try {
const result = await authApi.login({email, password});
const { token } = result.data;
this.$cookie.set('accessToken', token, 1000);
} catch (err) {
console.log(err);
}
try { },
const result = await authApi.login({email, password}); session: async function(evt) {
const { token } = result.data; const accessToken = this.$cookie.get('accessToken');
this.$cookie.set('accessToken', token, 1000); try {
} catch (err) { const result = await authApi.session(accessToken);
console.log(err); console.log(result);
} catch (err) {
console.log(err);
}
}
} }
},
currentUser: async function(evt) {
const accessToken = this.$cookie.get('accessToken');
try {
const result = await authApi.currentUser(accessToken);
console.log(result);
} catch (err) {
console.log(err);
}
}
} }
}
</script> </script>
<style scoped> <style scoped>