在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):nicolaslopezj/meteor-apollo-accounts开源软件地址(OpenSource Url):https://github.com/nicolaslopezj/meteor-apollo-accounts开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Meteor Apollo AccountsA implementation of Meteor Accounts only in GraphQL with Apollo. This package uses the Meteor Accounts methods in GraphQL, it's compatible with the accounts you have saved in your database and you may use apollo-accounts and Meteor's DPP accounts at the same time.
InstallingInstall on Meteor servermeteor add nicolaslopezj:apollo-accounts
yarn add graphql-loader Initialize the package. import {makeExecutableSchema} from 'graphql-tools'
import {loadSchema, getSchema} from 'graphql-loader'
import {initAccounts} from 'meteor/nicolaslopezj:apollo-accounts'
import typeDefs from './schema'
import resolvers from './resolvers'
// Load all accounts related resolvers and type definitions into graphql-loader
initAccounts({
loginWithFacebook: false,
loginWithGoogle: false,
loginWithLinkedIn: false,
loginWithPassword: true
})
// Load all your resolvers and type definitions into graphql-loader
loadSchema({typeDefs, resolvers})
// Gets all the resolvers and type definitions loaded in graphql-loader
const schema = getSchema()
const executableSchema = makeExecutableSchema(schema) Install on your apollo appMay or may not be the same app. npm install meteor-apollo-accounts Examples
TutorialsMethodsMeteor accounts methods, client side only. All methods are promises. loginWithPasswordLog the user in with a password. import { loginWithPassword } from 'meteor-apollo-accounts'
loginWithPassword({username, email, password}, apollo)
changePasswordChange the current user's password. Must be logged in. import { changePassword } from 'meteor-apollo-accounts'
changePassword({oldPassword, newPassword}, apollo)
logoutLog the user out. import { logout } from 'meteor-apollo-accounts'
logout(apollo)
createUserCreate a new user. import { createUser } from 'meteor-apollo-accounts'
createUser({username, email, password, profile}, apollo)
verifyEmailMarks the user's email address as verified. Logs the user in afterwards. import { verifyEmail } from 'meteor-apollo-accounts'
verifyEmail({token}, apollo)
forgotPasswordRequest a forgot password email. import { forgotPassword } from 'meteor-apollo-accounts'
forgotPassword({email}, apollo)
resetPasswordReset the password for a user using a token received in email. Logs the user in afterwards. import { resetPassword } from 'meteor-apollo-accounts'
resetPassword({newPassword, token}, apollo)
loginWithFacebookLogins the user with a facebook accessToken import { loginWithFacebook } from 'meteor-apollo-accounts'
loginWithFacebook({accessToken}, apollo)
loginWithGoogleLogins the user with a google accessToken import { loginWithGoogle } from 'meteor-apollo-accounts'
loginWithGoogle({accessToken}, apollo)
onTokenChangeRegister a function to be called when a user is logged in or out. import { onTokenChange } from 'meteor-apollo-accounts'
onTokenChange(function () {
console.log('token did change')
apollo.resetStore()
}) userIdReturns the id of the logged in user. import { userId } from 'meteor-apollo-accounts'
async function () {
console.log('The user id is:', await userId())
} React-Native usage//First you'll need to import the Storage library that you'll use to store the user details (userId, tokens...),
// AsyncStorage is highly recommended.
import {
...
AsyncStorage
} from 'react-native';
import { loginWithPassword, userId, setTokenStore} from 'meteor-apollo-accounts'
// Then you'll have to define a TokenStore for your user data using setTokenStore
// (for instance when your component is mounted):
setTokenStore({
set: async function ({userId, token, tokenExpires}) {
await AsyncStorage.setItem('Meteor.userId', userId)
await AsyncStorage.setItem('Meteor.loginToken', token)
// AsyncStorage doesn't support Date type so we'll store it as a String
await AsyncStorage.setItem('Meteor.loginTokenExpires', tokenExpires.toString())
},
get: async function () {
return {
userId: await AsyncStorage.getItem('Meteor.userId'),
token: await AsyncStorage.getItem('Meteor.loginToken'),
tokenExpires: await AsyncStorage.getItem('Meteor.loginTokenExpires')
}
}
})
// Finally, you'll be able to use asynchronously any method from the library:
async login (event) {
event.preventDefault();
try {
const id_ = await loginWithPassword({ "email", "password" }, this.client)
this.client.resetStore()
} catch (error) {
}
} Contributors |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论