2016-09-08 8 views
1

내 로컬 Horizion 서버에서 인증되지 않은 컬렉션에 액세스하려고합니다.Horizion.io 공용 읽기 액세스가 가능한 컬렉션

는 여기가 요청을 얼마나

다음
[collections.developerProfiles] 

[collections.users] 

[groups.default.rules.read_public_profile] 
template = "collection('developerProfiles').find({id: any()})" 

[groups.authenticated.rules.store_message] 
template = "collection('developerProfiles').store({id: any(), comments: any(), score: any()})" 

[groups.default.rules.read_current_user] 
template = "collection('users').find({id: userId()})" 

가 내 schema.toml이다. 처리되지 않은 오류 : 오류 : 인증되지 않은 연결이 허용되지 않습니다 여기

const ProfileCollection = _horizon('developerProfiles'); 

    ProfileCollection.find({ 
     id: 'someId' 
    }).fetch().subscribe(collection => { 
     console.log('collection', collection); 
    }) 

소켓을 통해 오류입니다.

내 질문 : 왜 인증은 인증 된 경우에만 작동합니까? 기본 규칙을 정의 할 때? 내가 여기서 무엇을 놓치고 있는지.

+0

헤이 카를로스, 그냥 몇 가지 실행 테스트. 'ProfileCollection.find'를 unauthenticated로 실행하려고 할 때 당신의 dev 콘솔에 "Operation not permitted"출력이 나오는지 확인하는 것뿐입니다. – dalanmiller

+0

다음 오류가 발생합니다. auth.js : 171Uncaught 오류 : 토큰을 사용하여 인증하려고 시도했지만 토큰이 존재하지 않습니다. 요청한 리소스가 공개이어야하므로 별다른 문제가 없습니다. –

+0

도움이된다면 @ horizon/client와의 반응을 사용하고 있습니다. 문서의 모든 권한을 시도한 것 같습니다. –

답변

1

나는 그것을 알아 냈다!

인증되지 않은 사용자가 컬렉션을 사용할 수있게하려면 다음을 수행해야합니다.

1) 호라이즌에 대한 연결

const _horizon = Horizon({ 
    authType: 'unauthenticated' 
}); 

2) 권한

[groups.default.rules.read_public_profile] 
template = "collection('developerProfiles').find({id: any()})" 

3) 내가 없어진 것을 인증 설정()

allow_unauthenticated: true 
+1

나는 당신의 코멘트를 본 후에 이렇게 말하기 위해 여기에왔다 : D, 당신은 기본적으로 두개의 코드 경로가 필요하다. 하나는 사용자가 (horizon.hasAuthToken()을 사용하여) 인증했기 때문에 하나의 토큰을 가지며 두 번째 코드 경로는 not-yet-authenticated ('horizon.hasAuthToken()'은 false를 반환 할 것이다). 후자의 경우 여기에 표시된 것처럼'authType : 'unauthenticated'를 사용합니다. – dalanmiller

+1

정확히 !!! 나는 어려운 길을 배웠다 ... 사랑한다. 넌 내 마음을 읽고있어. –