Spotify.access will be checker for full access

This commit is contained in:
James Barnsley
2017-08-04 22:33:49 +12:00
parent c2b8cfb346
commit e1ee57bdad
15 changed files with 100 additions and 92 deletions

View File

@ -201,7 +201,7 @@ const CoreMiddleware = (function(){
break
case 'spotify':
if (store.getState().spotify.authorized && store.getState().spotify.me){
if (store.getState().spotify.authorization && store.getState().spotify.me){
playlist.can_edit = (helpers.getFromUri('playlistowner',playlist.uri) == store.getState().spotify.me.id)
}
}
@ -225,7 +225,7 @@ const CoreMiddleware = (function(){
break
case 'spotify':
if (store.getState().spotify.authorized && store.getState().spotify.me){
if (store.getState().spotify.authorization && store.getState().spotify.me){
playlist.can_edit = (helpers.getFromUri('playlistowner',playlist.uri) == store.getState().spotify.me.id)
}
}

View File

@ -83,10 +83,10 @@ const localstorageMiddleware = (function(){
case 'SPOTIFY_AUTHORIZATION_GRANTED':
var spotify = JSON.parse( localStorage.getItem('spotify') );
if( !spotify ) spotify = {};
Object.assign(
spotify,{
authorized: true,
spotify = Object.assign(
{},
(spotify ? spotify : {}),
{
authorization: action.data,
access_token: action.data.access_token,
refresh_token: action.data.refresh_token,
@ -97,16 +97,19 @@ const localstorageMiddleware = (function(){
break;
case 'SPOTIFY_AUTHORIZATION_REVOKED':
console.log('local',action)
var spotify = JSON.parse( localStorage.getItem('spotify') );
if( !spotify ) spotify = {};
Object.assign(
spotify,{
authorized: false,
spotify = Object.assign(
{},
(spotify ? spotify : {}),
{
authorization: false,
access_token: false,
refresh_token: false,
token_expiry: false
}
);
console.log(spotify)
localStorage.setItem('spotify', JSON.stringify(spotify));
break;

View File

@ -335,6 +335,12 @@ const PusherMiddleware = (function(){
authorization_url: (action.config.authorization_url ? action.config.authorization_url : null),
backend_username: (action.config.spotify_username ? action.config.spotify_username : null)
}))
// Get our backend_username user
if (store.getState().spotify.access !== 'none' && (!store.getState().core.users || !store.getState().core.users[action.config.spotify_username])){
store.dispatch(spotifyActions.getUser(action.config.spotify_username))
}
next( action )
break

View File

@ -112,7 +112,7 @@ function getToken( dispatch, getState ){
function refreshToken( dispatch, getState ){
return new Promise( (resolve, reject) => {
if (getState().spotify.authorized){
if (getState().spotify.authorization && getState().spotify.authentication_provider == 'http_api'){
$.ajax({
method: 'GET',
@ -204,7 +204,7 @@ export function authorizationGranted( data ){
return { type: 'SPOTIFY_AUTHORIZATION_GRANTED', data: data }
}
export function authorizationRevoked(){
export function revokeAuthorization(){
return { type: 'SPOTIFY_AUTHORIZATION_REVOKED' }
}

View File

@ -68,7 +68,7 @@ const SpotifyMiddleware = (function(){
break
case 'SPOTIFY_CREATE_PLAYLIST':
if( !store.getState().spotify.authorized ){
if( !store.getState().spotify.authorization ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
return
}
@ -78,7 +78,7 @@ const SpotifyMiddleware = (function(){
case 'SPOTIFY_REMOVE_PLAYLIST_TRACKS':
var playlist = state.core.playlists[action.key]
if( !store.getState().spotify.authorized ){
if( !store.getState().spotify.authorization ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
return
}
@ -92,7 +92,7 @@ const SpotifyMiddleware = (function(){
case 'SPOTIFY_ADD_PLAYLIST_TRACKS':
if( !store.getState().spotify.authorized ){
if( !store.getState().spotify.authorization ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
return
}
@ -102,7 +102,7 @@ const SpotifyMiddleware = (function(){
case 'SPOTIFY_REORDER_PLAYLIST_TRACKS':
if( !store.getState().spotify.authorized ){
if( !store.getState().spotify.authorization ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
return
}
@ -117,7 +117,7 @@ const SpotifyMiddleware = (function(){
case 'SPOTIFY_SAVE_PLAYLIST':
if( !store.getState().spotify.authorized ){
if( !store.getState().spotify.authorization ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
return
}

View File

@ -18,7 +18,7 @@ export default function reducer(spotify = {}, action){
var spotify = Object.assign({},spotify,action.config)
let access = 'none'
if (spotify.authentication_provider == 'http_api' && spotify.authorized){
if (spotify.authentication_provider == 'http_api' && spotify.authorization){
access = 'full'
} else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
access = 'limited'
@ -27,7 +27,7 @@ export default function reducer(spotify = {}, action){
return spotify
case 'PUSHER_SPOTIFY_TOKEN':
if( spotify.authorized ) return spotify;
if( spotify.authorization ) return spotify;
return Object.assign({}, spotify, {
authorizing: false,
authorization: false,