# AuthService.refreshToken custom logic

```ts
/* ------------------------- start custom logic here ------------------------ */
if (!body.data?.refresh_token) throw new exceptions.UnprocessableEntityException('Refresh token is required');
const authManager = new AuthManager();

const decodedToken = authManager.decodeToken(body.data.refresh_token);
if (!decodedToken) {
  throw new exceptions.UnauthorizedException('Invalid refresh token');
}
const payload = decodedToken;
if (authData.current?.user?._id && payload._id !== authData.current.user._id)
  throw new exceptions.UnauthorizedException('Invalid refresh token');
const token = authManager.generateToken(payload, payload.space || 'default', false, config.security.jwt);
const refresh_token = authManager.generateToken(payload, payload.space || 'default', true, config.security.jwt);

const doc = await this.userModel.findOne({ _id: payload._id, is_deleted: false });
if (!doc) throw new exceptions.UnauthorizedException('User not found');
if (doc.attributes.is_suspended) throw new exceptions.UnauthorizedException('User suspended');

result.data = {
  user: mapDocumentToExposed(doc),
  token,
  refresh_token
};
/* -------------------------- end custom logic here ------------------------- */
```

