Skip to content

Commit 0a4c980

Browse files
Fix bug where v0.6.0 migration would break data when cloning an outdated repo
1 parent e83a351 commit 0a4c980

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/lib/server/auth/tokens.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ export async function validateToken(token: string): Promise<Infer<typeof JwtPayl
8888
// Token data format is incorrect
8989
throw Error('Token data is in incorrect format');
9090
}
91+
// Ensure the user ID exists
92+
if (!(data.uid in config.auth)) {
93+
// console.log(config.auth);
94+
// console.log(data);
95+
throw Error('This session does not map to a valid user');
96+
}
9197
// Ensure that the session isn't in our revoked list
9298
if (data.sessionId in config.auth[data.uid].sessions.revokedSessions) {
9399
throw Error('This session has been revoked');
@@ -137,6 +143,7 @@ export async function validateTokenFromRequest(req: { request: Request, cookies:
137143
error(401, 'A token is required to access this endpoint');
138144
}
139145
const data = await validateToken(token).catch(e => {
146+
console.log(e);
140147
// Remove token from cookies, as it is invalid
141148
req.cookies.delete('token', { path: '/' });
142149
error(401, `${e}`);

src/lib/server/data/migrations/v0.5.0.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { moveLocalConfig, updateConfigVersions } from './shared';
1212
import { unsafeLoadLocalConfig } from './unsafeLoad';
1313
import { setLocalConfig } from '../localConfig';
1414
import { authIsSetUp } from '../dataDir';
15+
import semver from 'semver';
1516

1617
export default async function migrate(dataDir: string, privateDataDir: string) {
1718
await moveLocalConfig(dataDir, privateDataDir);
@@ -25,6 +26,11 @@ async function updateLocalConfig(privateDataDir: string) {
2526
// Too lazy to make this type-safe
2627
const config = await unsafeLoadLocalConfig(privateDataDir) as any;
2728

29+
// If local config version is already v0.6.0 or greater, do nothing
30+
if (semver.gte(config.version, 'v0.6.0')) {
31+
return;
32+
}
33+
2834
config.keyPath = null;
2935

3036
const userInfo = config.auth;

0 commit comments

Comments
 (0)