代码之家  ›  专栏  ›  技术社区  ›  Eskel

无法读取未定义的属性'token\u data'

  •  1
  • Eskel  · 技术社区  · 8 年前

    我已经用密码验证了用户。为什么需要代币?还是权限问题?似乎这些状态没有被预期/处理。

    打开默认领域时出错:

    Cannot read property token_data of undefined

    Unhandled session token

    import React, { Component } from 'react'
    import { FlatList } from 'react-native'
    import Realm from 'realm'
    
    export default class RealmTest extends React.Component {
        constructor(props) {
            super(props);
            this.state = { realm: null };
        }
    
        componentWillMount() {
            const authURL  = 'https://duel.de1a.cloud.realm.io'
            const realmURL = 'realms://duel.de1a.cloud.realm.io'
            const username = 'test'
            const password = 'test'
    
            Realm.Sync.User.login(authURL, username, password)
            .then((user) => {
                //Realm.open({
                let realm = new Realm({
                    schema: [ { name: 'Dog', properties: { name: 'string' } } ],
                    sync: { user, url: realmURL},
                    //schemaVersion: 1
                })
                //.then((realm) => {
                const dogs = realm.objects('Dog');
                dogs.addListener(() => {
                    this.forceUpdate();
                });
                this.setState({ realm });
                //});
            })
            .catch(error => {
                console.warn("Authentication failed")
            });
        }
    
        renderList(realm) {
            if (! realm) {
                return <Text>"No realm objects"</Text>
            }
            else {
                return (
                    <FlatList
                        data={realm.objects('Dog')}
                        keyExtractor={(item) => item.name}
                        renderItem={({item}) => <Text>{item.name}</Text>}
                    />
                )
            }
        }
    
        render() {
            const info = this.state.realm
            ? 'Number of dogs in this Realm: ' + this.state.realm.objects('Dog').length
            : 'Loading...';
    
            return (
                <View>
                    {this.renderList(this.state.realm)}
                    <Text>{info}</Text>
                </View>
            );
        }
    }
    
    0 回复  |  直到 8 年前
    推荐文章