Notification API Error: 'User Not Logged In'

I’ve been trying to build a server that will send out push notifications to my expo app.

Right now, my fetch request keeps getting the following error:
{ err: ‘Not logged in.’,
_isApiError: true,
code: ‘USER_NOT_LOGGED_IN’ }

Do I need to login on my server? If so, how?

Thanks

Hi @matthewjgunton, this is the response from the Expo API, or from your own server?

Have you tried looking at the Expo server SDKs?

@charliecruzan
I’m making a fetch post request to the Expo API from my server.
My request is returning that error

Can you share the request? I haven’t seen this before

Below is the function on my server

function sendNotification(token){

return new Promise((resolve, reject)=> {
if(!isValidToken(token)){
reject(“invalid token”);
}

const PUSH_ENDPOINT = "https://exp.host/--/api/v2";

fetch(PUSH_ENDPOINT, {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    to: token,
    sound: 'default',
    title: 'Greetings!',
    body: 'from me!'
  }),
})
.then(response => response.json())
.then( (data) => {
  resolve(data);
}).catch( (e)=> {
  reject(e);
})

})

}

No, I just sent a notification through my CLI without being logged in to any Expo account.

Can you try sending from your CLI rather/with the Expo PN tool and see if those work? Also, try removing the sound field from your body

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.