session
This commit is contained in:
@@ -12,7 +12,6 @@ function login(data) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function register(data) {
|
||||
const { email, name, password } = data;
|
||||
return axios({
|
||||
@@ -26,7 +25,7 @@ function register(data) {
|
||||
});
|
||||
}
|
||||
|
||||
function currentUser(token) {
|
||||
function session(token) {
|
||||
return axios({
|
||||
method: 'get',
|
||||
url: '/api/users',
|
||||
@@ -38,6 +37,6 @@ function currentUser(token) {
|
||||
|
||||
export default {
|
||||
login,
|
||||
currentUser,
|
||||
session,
|
||||
register
|
||||
}
|
||||
@@ -8,48 +8,46 @@
|
||||
<button type="submit">확인</button>
|
||||
</form>
|
||||
|
||||
<button type="button" @click="currentUser">세션확인</button>
|
||||
<button type="button" @click="session">세션확인</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import authApi from "../../api/authApi";
|
||||
|
||||
export default {
|
||||
name: "Login",
|
||||
data() {
|
||||
return {
|
||||
email: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit: async function(evt) {
|
||||
evt.preventDefault();
|
||||
export default {
|
||||
name: "Login",
|
||||
data() {
|
||||
return {
|
||||
email: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit: async function(evt) {
|
||||
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});
|
||||
const { token } = result.data;
|
||||
this.$cookie.set('accessToken', token, 1000);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
},
|
||||
session: async function(evt) {
|
||||
const accessToken = this.$cookie.get('accessToken');
|
||||
try {
|
||||
const result = await authApi.session(accessToken);
|
||||
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>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user