xxxxxxxxxx
hi.
issue 1 :SQLSTATE[42000]: Syntax error or access violation: 1055 'laravel.users.name' isn't in GROUP BY.
solution:
short answer:
in config/database.php --> "mysql" array , set 'strict'=>false to disable all.
or .
You can leave 'strict' => true and add modes to "mysql" option in:
'mysql' => [
.
'strict' => true,
'modes' => [
//'ONLY_FULL_GROUP_BY', // Disable this to allow grouping by one column
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION'
],
]
issue2 : Malformed UTF-8 characters, possibly incorrectly encoded.
solution:
untill now you fixed just for english language messages . if you want to fix for persian language messages too, you should try this:
1.first publish chatify controller (if you want to know how to publish it visit this site : publish_controller ).
go to : app/http/controllers/vendor/chatify/messagesController.php -->public function getContacts(){} .
add this $contacts= mb_convert_encoding($contacts, 'UTF-8', 'UTF-8'); to messagesController.php file , like below:
public function getContacts(Request $request)
{
if (count($usersList) > 0) {
$contacts = '';
foreach ($usersList as $user) {
$contacts .= Chatify::getContactItem($user);
}
} else {
$contacts = '<p class="message-hint center-el"><span>Your contact list is empty</span></p>';
}
$contacts= mb_convert_encoding($contacts, 'UTF-8', 'UTF-8');
return Response::json([
'contacts' => $contacts,
'total' => $users->total() ?? 0,
'last_page' => $users->lastPage() ?? 1,
], 200);
}
good luck
xxxxxxxxxx
export const isTokenExpired = (token: string): boolean => {
const decoded = jwtDecode<DecodedToken>(token)
return decoded.exp * 1000 < Date.now() // Convert exp to milliseconds
}
// Helper function to get token expiration time from token
export function getTokenExpirationTime(token: string): number {
const payload = JSON.parse(atob(token.split('.')[1]))
return payload.exp * 1000
}
export const validateAccessToken = async () => {
const session = (await getSession()) as CustomSession | null
if (!session) return
const accessToken = session.accessToken
const timeLeft = accessToken ? getTokenExpirationTime(accessToken) - Date.now() : 0
// Schedule token refresh a few minutes before expiration
const refreshTimeout = setTimeout(async () => {
try {
await getValidAccessToken(session)
} catch (error) {
console.error(error)
}
}, Math.max(timeLeft - 5 * 60 * 1000, 0)) // Refresh 5 minutes before expiration
// Clear timeout if component unmounts
return () => clearTimeout(refreshTimeout)
}
//auth.ts
//jwt callback
async jwt({ token, profile, user }) {
const userWithTokens = user as CustomUser
if (user) {
token.accessToken = userWithTokens.accessToken //store accesstoken in the token aswell
token.refreshToken = userWithTokens.refreshToken
token.accessTokenExpires = userWithTokens.accessTokenExpires;
}
if (profile) {
token.sub = profile.sub ?? ''
token.name = profile['cognito:username'] as string
}
// If the token is still valid, return it
if (Date.now() < (token.accessTokenExpires as number)) {
return token
}
// Token has expired, try to refresh it
const refreshedToken = await refreshAccessToken(
token?.refreshToken as string,
token?.name as string
)
if (refreshedToken) {
return {
token,
accessToken: refreshedToken.accessToken,
accessTokenExpires: refreshedToken.accessTokenExpires,
}
}
return {
token,
error: 'RefreshAccessTokenError',
}
},
export const refreshAccessToken = async (refreshToken: string, username: string) => {
const secretHash = await getSecretHash(username)
try {
const command = new InitiateAuthCommand({
AuthFlow: 'REFRESH_TOKEN_AUTH',
ClientId: clientId,
AuthParameters: {
REFRESH_TOKEN: refreshToken,
SECRET_HASH: secretHash,
},
})
const response = await cognitoClient.send(command)
const newAccessToken = response.AuthenticationResult?.AccessToken
const expiresIn = response.AuthenticationResult?.ExpiresIn || 3600
return {
accessToken: newAccessToken,
accessTokenExpires: Date.now() + expiresIn * 1000, // Calculate expiration time
}
} catch (error) {
console.error('Error refreshing access token:', error)
return null // Return null if there’s an error
}
}