import Tozny from 'tozny-browser-sodium-sdk'
const realmName = process.env.VUE_APP_REALM_NAME;
const appName = process.env.VUE_APP_APP_NAME;
const brokerUrl = process.env.VUE_APP_BROKER_URL;
const registrationToken = process.env.VUE_APP_REGISTRATION_TOKEN;
"brokerTargetUrl" : brokerUrl
const tozIDConfig = Tozny.Identity.Config.fromObject(realmConfig)
const tozId = new Tozny.Identity(tozIDConfig)
export default new Vuex.Store({
SET_TOZNY_CLIENT(state, payload){
state.toznyClient = payload
const base64Url = token.split('.')[1]
const base64 = base64Url.replace('-', '+').replace('_', '/')
const claims = JSON.parse(window.atob(base64))
state.name = claims['preferred_username'];
delete localStorage.clear();
async setToznyClient({commit}, payload){
commit('SET_TOZNY_CLIENT', payload)
async rehydrateTozny({commit}){
const client = tozId.fromObject(localStorage.getItem('toznyClient'))
commit('SET_TOZNY_CLIENT', client)
const token = await client.token()
commit('SET_NAME', token)
async login({commit}, payload){
const res = await tozId.login(payload.email, payload.pass)
localStorage.setItem('toznyClient',JSON.stringify(res.serialize()))
commit('SET_TOZNY_CLIENT', res)
const token = await res.token()
commit('SET_NAME', token)
console.log("Bad password")
async requestReset({commit}, payload){
// Requesting a reset from the TozID service and since
// our realm is configured to let TozID broker the
// reset our email will be delivered by Tozny
// (if you toggle OFF the setting in your realm settings then this will fail)
const res = await tozId.initiateRecovery(payload.email)
async completeRecovery({commit}, payload){
// First we verify the query parameters from the recovery link
// and pass them to the complete recovery method and then
// the next function performs the password change
const res = await tozId.completeRecovery(payload.otp, payload.noteId)
await res.changePassword(payload.pass)
async register({commit}, payload){
const res = await tozId.register(payload.email, payload.pass, registrationToken, payload.email)
localStorage.setItem('toznyClient',JSON.stringify(res.serialize()))
commit('SET_TOZNY_CLIENT', res)
const token = await res.token()
commit('SET_NAME', token)
loggedIn: state => !!state.toznyClient