justoverclockl/flarum-ext-welcomebox

Error if user doesn't disclose their last online date

Closed this issue · 2 comments

I have not personally experienced this error but looking at the code it's very likely this is the cause of an error reported on the forums.

Report on forum https://discuss.flarum.org/d/32070-cant-open-posts-in-a-forum/9 (poster doesn't own the website)

The problem seems to be this line

const lastseenAt = user.data.attributes.lastSeenAt.slice(0, 10);

If the user discloseOnline preference is set to false, the attribute won't exist and the error TypeError: t.data.attributes.lastSeenAt is undefined will be thrown.

This is the code in Flarum that determines when that attribute is available https://github.com/flarum/framework/blob/v1.6.2/framework/core/src/Api/Serializer/UserSerializer.php#L32-L36

Additionally, accessing the attribute through model.data.attributes is bad practice. There doesn't seem to be any reason not to use user.lastSeenAt() instead. Then check if the returned value is not undefined before continuing.

Thx Clark I will fix this asap.
@clarkwinkelmann but i think that this variable is not used

should be fixed in the latest version!