Initial migration to new session based auth system with AllAuth
This commit is contained in:
@@ -17,10 +17,12 @@ export const load = (async (event) => {
|
||||
let previous = null;
|
||||
let count = 0;
|
||||
let adventures: Adventure[] = [];
|
||||
let sessionId = event.cookies.get('sessionid');
|
||||
let initialFetch = await fetch(`${serverEndpoint}/api/collections/?order_by=updated_at`, {
|
||||
headers: {
|
||||
Cookie: `${event.cookies.get('auth')}`
|
||||
}
|
||||
Cookie: `sessionid=${sessionId}`
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
if (!initialFetch.ok) {
|
||||
console.error('Failed to fetch visited adventures');
|
||||
@@ -72,34 +74,9 @@ export const actions: Actions = {
|
||||
formDataToSend.append('start_date', start_date || '');
|
||||
formDataToSend.append('end_date', end_date || '');
|
||||
formDataToSend.append('link', link || '');
|
||||
let auth = event.cookies.get('auth');
|
||||
let sessionid = event.cookies.get('sessionid');
|
||||
|
||||
if (!auth) {
|
||||
const refresh = event.cookies.get('refresh');
|
||||
if (!refresh) {
|
||||
return {
|
||||
status: 401,
|
||||
body: { message: 'Unauthorized' }
|
||||
};
|
||||
}
|
||||
let res = await tryRefreshToken(refresh);
|
||||
if (res) {
|
||||
auth = res;
|
||||
event.cookies.set('auth', auth, {
|
||||
httpOnly: true,
|
||||
sameSite: 'lax',
|
||||
expires: new Date(Date.now() + 60 * 60 * 1000), // 60 minutes
|
||||
path: '/'
|
||||
});
|
||||
} else {
|
||||
return {
|
||||
status: 401,
|
||||
body: { message: 'Unauthorized' }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!auth) {
|
||||
if (!sessionid) {
|
||||
return {
|
||||
status: 401,
|
||||
body: { message: 'Unauthorized' }
|
||||
@@ -119,7 +96,7 @@ export const actions: Actions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
Cookie: auth
|
||||
Cookie: `sessionid=${sessionid}; csrftoken=${csrfToken}`
|
||||
},
|
||||
body: formDataToSend
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user