<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)
export default new Vuex.Store({
plugins: [createPersistedState()],
state: {
status: '',
token: localStorage.getItem('token') || '',
user: {},
project: {}
},
mutations: {
// User
auth_request(state) {
state.status = 'loading'
},
auth_success(state, {
token,
user
}) {
state.status = 'success'
state.token = token
state.user = user
},
auth_error(state) {
state.status = 'error'
},
logout(state) {
state.status = ''
state.token = ''
},
// Project
getProject_success(state, {
project
}) {
state.status = 'success'
state.project = project
},
getProject_error(state) {
state.status = 'error'
}
},
actions: {
login({
commit
}, user) {
return new Promise((resolve, reject) => {
commit('auth_request')
axios.post(process.env.VUE_APP_USER_API + '/login', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
logemail: user.email,
logpassword: user.password,
})
.then(resp => {
const token = resp.data.token;
const user = resp.data.user;
console.log(resp.data.user);
localStorage.setItem('token', token)
axios.defaults.headers.common['Authorization'] = token
commit('auth_success', {
token,
user
})
resolve(resp)
})
.catch(err => {
commit('auth_error')
localStorage.removeItem('token')
reject(err)
})
})
},
register({
commit
}, user) {
return new Promise((resolve, reject) => {
commit('auth_request')
axios.post(process.env.VUE_APP_USER_API + '/create', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
email: user.email,
password: user.password,
passwordConf: user.passwordConf
})
.then(resp => {
const token = resp.data.token
const user = resp.data.user
localStorage.setItem('token', token)
axios.defaults.headers.common['Authorization'] = token
commit('auth_success', token, user)
resolve(resp)
})
.catch(err => {
console.log("Error: ", err);
commit('auth_error', err)
localStorage.removeItem('token')
reject(err)
})
})
},
logout({
commit
}) {
return new Promise((resolve, reject) => {
commit('logout')
localStorage.removeItem('token')
delete axios.defaults.headers.common['Authorization']
resolve()
.catch(err => {
console.log("Error: ", err);
commit('auth_error', err)
localStorage.removeItem('token')
reject(err)
})
})
},
getProject({
commit
}, user) {
return new Promise((resolve, reject) => {
commit('auth_request')
axios.get(process.env.VUE_APP_PROJECT_API + '/projects?userId='+ user.email)
.then(resp => {
const project = resp.data.project
commit('getProject_success', {
project
})
resolve(resp)
})
.catch(err => {
commit('getProject_error')
reject(err)
})
})
},
},
getters: {
getUser: state => { return state.user },
getProject: state => { return state.project },
isLoggedIn: state => !!state.token,
authStatus: state => state.status
}
})
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |