session
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user