Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

SC.connect doesn't make sure that oauth_token is valid

Aperta
#32 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript

Direzione di ricerca

Start by tracing SC.connect, SC.isConnected, and config.set, focusing on how an existing oauth_token is handled and how the /me request reports a 401. Confirm that an invalid token can be cleared or rejected without reloading the page, then verify the reconnect flow and existing authentication behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

With the previous SDK version, I could avoid a login popup every pageload by doing this:

var params = {
    client_id:    '...',
    redirect_uri: '...',
    scope:        'non-expiring'
};
var auth = localStorage.getItem('auth-token');
if (auth) {
    params.access_token = auth;
}
SC.initialize(params);

// ...

function connectionCallback() {
    localStorage.setItem('auth-token', SC.accessToken());
    onConnected();
    SC.get('/me', gotUserdata);
}

if (SC.isConnected()) {
    // make sure we really are
    SC.get('/me', function(user, err) {
        if (!!err) {
            // Error exists, connectify
            SC.connect(connectionCallback);
        } else {
            // We're in
            onConnected();
            gotUserdata(user);
        }
    });
} else {
    SC.connect(connectionCallback);
}

However now isConnected is simply

  isConnected () {
    return config.get('oauth_token') !== undefined;
  },

and connect does this:

  // resolve immediately when oauth_token is set
  const oauth_token = config.get('oauth_token');
  if (oauth_token) {
    return new Promise((resolve) => { resolve({oauth_token}); });
  }

I thought I could get around this by checking for a 401 when fetching /me, but unfortunately I can't null out the oauth_token config value:

  set(key, value) {
    if (value) {
      config[key] = value;
    }
  }

The best I can think of now is to delete the localStorage value and reload the page, but that's not very nice.

Lingua principale
JavaScript
Stelle
388
Fork
76
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di soundcloud/soundcloud-javascript

Tutte le issue di soundcloud/soundcloud-javascript

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.