We use VERB + あいだ(に)to express "while".
日本にいるあいだ に - While I'm in Japan
日本にいるあいだ - While I am in Japan
日本にいるあいだ - While I was in Japan
(The あいだ part of the sentence stays in the non-past. The tense is determined by the final verb.)
(The あいだ part of the sentence stays in the non-past. The tense is determined by the final verb.)
Here's a pair of examples that express basically the same thing, one with and one without に. Can you work out the difference?