Added loading indicator
This commit is contained in:
32
src/routes/private/api/google/auth/check/+server.ts
Normal file
32
src/routes/private/api/google/auth/check/+server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getAuthenticatedClient } from '$lib/google/auth/server';
|
||||
|
||||
/**
|
||||
* @description Verify the validity of a Google refresh token
|
||||
* @method POST
|
||||
* @param {Request} request
|
||||
* @returns {Response}
|
||||
*/
|
||||
export async function POST({ request }: { request: Request }): Promise<Response> {
|
||||
try {
|
||||
const { refreshToken } = await request.json();
|
||||
|
||||
if (!refreshToken) {
|
||||
return json({ error: 'Refresh token is required' }, { status: 400 });
|
||||
}
|
||||
|
||||
// Get an authenticated client. This will attempt to get a new access token,
|
||||
// which effectively validates the refresh token.
|
||||
const oauth2Client = getAuthenticatedClient(refreshToken);
|
||||
|
||||
// Attempt to get a new access token
|
||||
await oauth2Client.getAccessToken();
|
||||
|
||||
// If no error is thrown, the token is valid
|
||||
return json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Failed to verify Google refresh token:', error);
|
||||
// The token is likely invalid or revoked
|
||||
return json({ error: 'Invalid or expired refresh token' }, { status: 401 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user