index.js 793 字节
Newer Older
yu's avatar
yu 已提交
1 2 3 4

import {
	reactive
} from "vue";
5

yu's avatar
yu 已提交
6 7 8 9 10 11
import {
	ddp
} from "../../core/ddp";

export const user = reactive({})

12
export const Users = ddp.db.collection('users')
yu's avatar
yu 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
ddp.user.onChange((info) => {
	if (info) {
		for (const key in info) {
			user[key] = info[key]
		}
	} else {
		for (const key in user) {
			delete user[key]
		}
	}
})

export const signin = async (data) => {
	if (!data.username || !data.password) return
	ddp.loginWithPassword(data.username, data.password).catch(err => {
		uni.showToast({
			title: '密码或者用户名错误'
		})
	});
};

export const signup = async (data) => {
	if (!data.username || !data.password || data.password !== data.password1) return
	ddp.createAccount(data.username, data.password).catch(err => {
		uni.showToast({
			title: '注册失败'
		})
	});
};